3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * A queue is an object (usually backed by some persistent data store)
30 * which stores a list of tasks or messages for use by other processes.
32 * This would ideally be an interface, but it's handy to specify the
33 * "function __construct()" and the "$name" handling
35 * Note: This interface closely parallels the DrupalQueueInterface.
37 abstract class CRM_Queue_Queue
{
45 * Create a reference to queue. After constructing the queue, one should
46 * usually call createQueue (if it's a new queue) or loadQueue (if it's
47 * known to be an existing queue).
49 * @param $queueSpec, array with keys:
50 * - type: string, required, e.g. "interactive", "immediate", "stomp", "beanstalk"
51 * - name: string, required, e.g. "upgrade-tasks"
52 * - reset: bool, optional; if a queue is found, then it should be flushed; default to TRUE
53 * - (additional keys depending on the queue provider)
54 */ function __construct($queueSpec) {
55 $this->_name
= $queueSpec['name'];
59 * Determine the string name of this queue
68 * Perform any registation or resource-allocation for a new queue
70 abstract function createQueue();
73 * Perform any loading or pre-fetch for an existing queue.
75 abstract function loadQueue();
78 * Release any resources claimed by the queue (memory, DB rows, etc)
80 abstract function deleteQueue();
83 * Check if the queue exists
87 abstract function existsQueue();
90 * Add a new item to the queue
92 * @param $data serializable PHP object or array
93 * @param $options queue-dependent options; for example, if this is a
94 * priority-queue, then $options might specify the item's priority
96 * @return bool, TRUE on success
98 abstract function createItem($data, $options = array());
101 * Determine number of items remaining in the queue
105 abstract function numberOfItems();
110 * @param $lease_time seconds
112 * @return object with key 'data' that matches the inputted data
114 abstract function claimItem($lease_time = 3600);
117 * Get the next item, even if there's an active lease
119 * @param $lease_time seconds
121 * @return object with key 'data' that matches the inputted data
123 abstract function stealItem($lease_time = 3600);
126 * Remove an item from the queue
128 * @param $item The item returned by claimItem
130 abstract function deleteItem($item);
133 * Return an item that could not be processed
135 * @param $item The item returned by claimItem
139 abstract function releaseItem($item);