From 5ee1a5c17df855a4c2b9b2cfd8026b9a8ef8b790 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 10 Feb 2022 19:12:23 -0800 Subject: [PATCH] CRM_Queue_Queue_* - Retain a copy of `$queueSpec` --- CRM/Queue/Queue.php | 29 +++++++++++++++++++-------- tests/phpunit/CRM/Queue/QueueTest.php | 2 ++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CRM/Queue/Queue.php b/CRM/Queue/Queue.php index 87bad2f9e907..a8b98b8b64ae 100644 --- a/CRM/Queue/Queue.php +++ b/CRM/Queue/Queue.php @@ -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 @@ public function getName() { 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 */ diff --git a/tests/phpunit/CRM/Queue/QueueTest.php b/tests/phpunit/CRM/Queue/QueueTest.php index d2ef5b06a4db..6890b29754ab 100644 --- a/tests/phpunit/CRM/Queue/QueueTest.php +++ b/tests/phpunit/CRM/Queue/QueueTest.php @@ -72,6 +72,8 @@ public function testBasicUsage($queueSpec) { $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',