Skip to content

Commit

Permalink
Merge pull request #22797 from totten/master-queue-spec
Browse files Browse the repository at this point in the history
(REF) CRM_Queue_Queue_* - Retain a copy of `$queueSpec`
  • Loading branch information
colemanw authored Feb 19, 2022
2 parents 6196859 + 5ee1a5c commit ba118f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 21 additions & 8 deletions CRM/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/CRM/Queue/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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',
Expand Down

0 comments on commit ba118f1

Please sign in to comment.