public function MemoryQueue::claimItem in Purge 8.3
Claims an item in the queue for processing.
Parameters
$lease_time: How long the processing is expected to take in seconds, defaults to an hour. After this lease expires, the item will be reset and another consumer can claim the item. For idempotent tasks (which can be run multiple times without side effects), shorter lease times would result in lower latency in case a consumer fails. For tasks that should not be run more than once (non-idempotent), a larger lease time will make it more rare for a given task to run multiple times in cases of failure, at the cost of higher latency.
Return value
On success we return an item object. If the queue is unable to claim an item it returns false. This implies a best effort to retrieve an item and either the queue is empty or there is some other non-recoverable problem.
If returned, the object will have at least the following properties:
- data: the same as what what passed into createItem().
- item_id: the unique ID returned from createItem().
- created: timestamp when the item was put into the queue.
Overrides QueueInterface::claimItem
1 call to MemoryQueue::claimItem()
- MemoryQueue::claimItemMultiple in src/
Plugin/ Purge/ Queue/ MemoryQueue.php - Claims multiple items from the queue for processing.
File
- src/
Plugin/ Purge/ Queue/ MemoryQueue.php, line 97
Class
- MemoryQueue
- A QueueInterface compliant volatile memory buffer queue.
Namespace
Drupal\purge\Plugin\Purge\QueueCode
public function claimItem($lease_time = 3600, $id = NULL) {
if ($id == NULL) {
$this
->bufferInitialize();
reset($this->buffer);
$id = key($this->buffer);
}
if (empty($this->buffer)) {
return FALSE;
}
if (!isset($this->buffer[$id])) {
return FALSE;
}
if ($this->buffer[$id][self::EXPIRE] === 0 || $this->buffer[$id][self::EXPIRE] !== 0 && time() > $this->buffer[$id][self::EXPIRE]) {
$this->buffer[$id][self::EXPIRE] = time() + $lease_time;
$item = new \stdClass();
$item->item_id = $id;
$item->data = unserialize($this->buffer[$id][self::DATA]);
$item->expire = $this->buffer[$id][self::EXPIRE];
$item->created = $this->buffer[$id][self::CREATED];
return $item;
}
else {
$id++;
return $this
->claimItem($lease_time, $id);
}
}