CRM_Queue_Queue_* - Retain a copy of `$queueSpec`
authorTim Otten <totten@civicrm.org>
Fri, 11 Feb 2022 03:12:23 +0000 (19:12 -0800)
committerTim Otten <totten@civicrm.org>
Sat, 19 Feb 2022 00:06:29 +0000 (16:06 -0800)
CRM/Queue/Queue.php
tests/phpunit/CRM/Queue/QueueTest.php

index 87bad2f9e9072fc8bca19fdfbaf50fa2eeb400cf..a8b98b8b64aef01441a21a8a6ed124ba09758a01 100644 (file)
@@ -25,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;
   }
 
   /**
@@ -52,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
    */
index d2ef5b06a4db850c8280c124707edad7c31820b3..6890b29754ab93c969e8d3ca6116eccca11ae8f5 100644 (file)
@@ -72,6 +72,8 @@ class CRM_Queue_QueueTest extends CiviUnitTestCase {
     $this->queue = $this->queueService->create($queueSpec);
     $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_queue');
     $this->assertTrue($this->queue instanceof CRM_Queue_Queue);
+    $this->assertEquals($queueSpec['name'], $this->queue->getSpec('name'));
+    $this->assertEquals($queueSpec['type'], $this->queue->getSpec('type'));
 
     $this->queue->createItem([
       'test-key' => 'a',