You are here

public function AcquiaPurgeQueueEfficient::claimItemMultiple in Acquia Purge 7

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

AcquiaPurgeInvalidationInterface[] 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 AcquiaPurgeQueueInterface::claimItemMultiple

1 call to AcquiaPurgeQueueEfficient::claimItemMultiple()
AcquiaPurgeQueueSmart::claimItemMultiple in lib/queue/AcquiaPurgeQueueSmart.php
Claims multiple items from the queue for processing.
1 method overrides AcquiaPurgeQueueEfficient::claimItemMultiple()
AcquiaPurgeQueueSmart::claimItemMultiple in lib/queue/AcquiaPurgeQueueSmart.php
Claims multiple items from the queue for processing.

File

lib/queue/AcquiaPurgeQueueEfficient.php, line 124
Contains EfficientQueue.

Class

AcquiaPurgeQueueEfficient
Efficient query bundling database queue.

Code

public function claimItemMultiple($claims = 10, $lease_time = 30) {
  $returned_items = $item_ids = array();

  // Retrieve all items in one query.
  $conditions = array(
    ':name' => $this->name,
    ':now' => time(),
  );
  $items = db_query_range('SELECT * FROM {queue} q
      WHERE name = :name AND ((expire = 0) OR (:now > expire))
      ORDER BY created, item_id
      ASC', 0, $claims, $conditions);

  // Iterate all returned items and unpack them.
  while ($item = $items
    ->fetchObject()) {
    $item_ids[] = (int) $item->item_id;
    $returned_items[] = new $this->class_queue_item((int) $item->created, unserialize($item->data), (int) $item->expire, (int) $item->item_id);
  }

  // Update the items (marking them claimed) in one query.
  if (count($returned_items)) {
    db_update('queue')
      ->fields(array(
      'expire' => time() + $lease_time,
    ))
      ->condition('item_id', $item_ids, 'IN')
      ->execute();
  }

  // Return the generated items, whether its empty or not.
  return $returned_items;
}