Merge pull request #22884 from civicrm/5.47
[civicrm-core.git] / CRM / Queue / Queue.php
index c270222888651280081ee54f0d02dc606e274136..a8b98b8b64aef01441a21a8a6ed124ba09758a01 100644 (file)
@@ -1,27 +1,11 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2020                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
@@ -41,22 +25,25 @@ abstract class CRM_Queue_Queue {
    */
   private $_name;
 
+  /**
+   * @var array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int}
+   * @see \CRM_Queue_Service::create()
+   */
+  protected $queueSpec;
+
   /**
    * Create a reference to queue. After constructing the queue, one should
    * usually call createQueue (if it's a new queue) or loadQueue (if it's
    * known to be an existing queue).
    *
-   * @param array $queueSpec
-   *   Array with keys:
-   *   - type: string, required, e.g. "interactive", "immediate", "stomp",
-   *     "beanstalk"
-   *   - name: string, required, e.g. "upgrade-tasks"
-   *   - reset: bool, optional; if a queue is found, then it should be
-   *     flushed; default to TRUE
-   *   - (additional keys depending on the queue provider).
+   * @param array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int} $queueSpec
+   *   Ex: ['name' => 'my-import', 'type' => 'SqlParallel']
+   *   The full definition of queueSpec is defined in CRM_Queue_Service.
+   * @see \CRM_Queue_Service::create()
    */
   public function __construct($queueSpec) {
     $this->_name = $queueSpec['name'];
+    $this->queueSpec = $queueSpec;
   }
 
   /**
@@ -68,6 +55,16 @@ abstract class CRM_Queue_Queue {
     return $this->_name;
   }
 
+  /**
+   * Get a property from the queueSpec.
+   *
+   * @param string $field
+   * @return mixed|null
+   */
+  public function getSpec(string $field) {
+    return $this->queueSpec[$field] ?? NULL;
+  }
+
   /**
    * Perform any registation or resource-allocation for a new queue
    */