3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * A queue is an object (usually backed by some persistent data store)
14 * which stores a list of tasks or messages for use by other processes.
16 * This would ideally be an interface, but it's handy to specify the
17 * "function __construct()" and the "$name" handling
19 * Note: This interface closely parallels the DrupalQueueInterface.
21 abstract class CRM_Queue_Queue
{
29 * @var array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int}
30 * @see \CRM_Queue_Service::create()
35 * Create a reference to queue. After constructing the queue, one should
36 * usually call createQueue (if it's a new queue) or loadQueue (if it's
37 * known to be an existing queue).
39 * @param array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int} $queueSpec
40 * Ex: ['name' => 'my-import', 'type' => 'SqlParallel']
41 * The full definition of queueSpec is defined in CRM_Queue_Service.
42 * @see \CRM_Queue_Service::create()
44 public function __construct($queueSpec) {
45 $this->_name
= $queueSpec['name'];
46 $this->queueSpec
= $queueSpec;
50 * Determine the string name of this queue.
54 public function getName() {
59 * Get a property from the queueSpec.
61 * @param string $field
64 public function getSpec(string $field) {
65 return $this->queueSpec
[$field] ??
NULL;
69 * Perform any registation or resource-allocation for a new queue
71 abstract public function createQueue();
74 * Perform any loading or pre-fetch for an existing queue.
76 abstract public function loadQueue();
79 * Release any resources claimed by the queue (memory, DB rows, etc)
81 abstract public function deleteQueue();
84 * Check if the queue exists.
88 abstract public function existsQueue();
91 * Add a new item to the queue.
94 * Serializable PHP object or array.
95 * @param array $options
96 * Queue-dependent options; for example, if this is a
97 * priority-queue, then $options might specify the item's priority.
99 abstract public function createItem($data, $options = []);
102 * Determine number of items remaining in the queue.
106 abstract public function numberOfItems();
111 * @param int $lease_time
115 * with key 'data' that matches the inputted data
117 abstract public function claimItem($lease_time = 3600);
120 * Get the next item, even if there's an active lease
122 * @param int $lease_time
126 * with key 'data' that matches the inputted data
128 abstract public function stealItem($lease_time = 3600);
131 * Remove an item from the queue.
133 * @param object $item
134 * The item returned by claimItem.
136 abstract public function deleteItem($item);
139 * Return an item that could not be processed.
141 * @param object $item
142 * The item returned by claimItem.
144 abstract public function releaseItem($item);