W3cubDocs

/Drupal 8

public function Memory::claimItem

public Memory::claimItem($lease_time = 30)

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

File

core/lib/Drupal/Core/Queue/Memory.php, line 63

Class

Memory
Static queue implementation.

Namespace

Drupal\Core\Queue

Code

public function claimItem($lease_time = 30) {
  foreach ($this->queue as $key => $item) {
    if ($item->expire == 0) {
      $item->expire = time() + $lease_time;
      $this->queue[$key] = $item;
      return $item;
    }
  }
  return FALSE;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Queue!Memory.php/function/Memory::claimItem/8.1.x