You are here

public function QueueBase::claimItemMultiple in Purge 8.3

Claims multiple items from the queue for processing.

Parameters

int $claims: Determines how many claims at once should be claimed from the queue. When the queue is unable to return as many items as requested it will return as much items as it can.

int $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

array[] On success we return a non-associative array with item objects. When the queue has no items that can be claimed, this doesn't return FALSE as claimItem() does, but an empty array instead.

If claims return, the objects have at least these 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::claimItemMultiple

1 method overrides QueueBase::claimItemMultiple()
MemoryQueue::claimItemMultiple in src/Plugin/Purge/Queue/MemoryQueue.php
Claims multiple items from the queue for processing.

File

src/Plugin/Purge/Queue/QueueBase.php, line 46

Class

QueueBase
Provides a ReliableQueueInterface compliant queue that holds queue items.

Namespace

Drupal\purge\Plugin\Purge\Queue

Code

public function claimItemMultiple($claims = 10, $lease_time = 3600) {
  $items = [];

  // This implementation emulates multiple item claiming and is NOT efficient,
  // but exists to provide a reliable API. Derivatives are invited to override
  // it, for example by one multi-row select database query.
  for ($i = 1; $i <= $claims; $i++) {
    if (($item = $this
      ->claimItem($lease_time)) === FALSE) {
      break;
    }
    $items[] = $item;
  }
  return $items;
}