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 * Create a reference to queue. After constructing the queue, one should
30 * usually call createQueue (if it's a new queue) or loadQueue (if it's
31 * known to be an existing queue).
33 * @param array $queueSpec
35 * - type: string, required, e.g. "interactive", "immediate", "stomp",
37 * - name: string, required, e.g. "upgrade-tasks"
38 * - reset: bool, optional; if a queue is found, then it should be
39 * flushed; default to TRUE
40 * - (additional keys depending on the queue provider).
42 public function __construct($queueSpec) {
43 $this->_name
= $queueSpec['name'];
47 * Determine the string name of this queue.
51 public function getName() {
56 * Perform any registation or resource-allocation for a new queue
58 abstract public function createQueue();
61 * Perform any loading or pre-fetch for an existing queue.
63 abstract public function loadQueue();
66 * Release any resources claimed by the queue (memory, DB rows, etc)
68 abstract public function deleteQueue();
71 * Check if the queue exists.
75 abstract public function existsQueue();
78 * Add a new item to the queue.
81 * Serializable PHP object or array.
82 * @param array $options
83 * Queue-dependent options; for example, if this is a
84 * priority-queue, then $options might specify the item's priority.
86 abstract public function createItem($data, $options = []);
89 * Determine number of items remaining in the queue.
93 abstract public function numberOfItems();
98 * @param int $lease_time
102 * with key 'data' that matches the inputted data
104 abstract public function claimItem($lease_time = 3600);
107 * Get the next item, even if there's an active lease
109 * @param int $lease_time
113 * with key 'data' that matches the inputted data
115 abstract public function stealItem($lease_time = 3600);
118 * Remove an item from the queue.
120 * @param object $item
121 * The item returned by claimItem.
123 abstract public function deleteItem($item);
126 * Return an item that could not be processed.
128 * @param object $item
129 * The item returned by claimItem.
131 abstract public function releaseItem($item);