You are here

public function AcquiaPurgeQueueEfficient::claimItem in Acquia Purge 7

SystemQueue::claimItem() doesn't included expired items in its query which means that it essentially breaks its own interface promise. Therefore we overload the implementation with one that does do this accurately. This should however flow back to core, which I'm doing as part of my D8 work.

Overrides SystemQueue::claimItem

1 call to AcquiaPurgeQueueEfficient::claimItem()
AcquiaPurgeQueueSmart::claimItem in lib/queue/AcquiaPurgeQueueSmart.php
SystemQueue::claimItem() doesn't included expired items in its query which means that it essentially breaks its own interface promise. Therefore we overload the implementation with one that does do this accurately. This should however flow back…
1 method overrides AcquiaPurgeQueueEfficient::claimItem()
AcquiaPurgeQueueSmart::claimItem in lib/queue/AcquiaPurgeQueueSmart.php
SystemQueue::claimItem() doesn't included expired items in its query which means that it essentially breaks its own interface promise. Therefore we overload the implementation with one that does do this accurately. This should however flow back…

File

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

Class

AcquiaPurgeQueueEfficient
Efficient query bundling database queue.

Code

public function claimItem($lease_time = 30) {

  // Claim an item by updating its expire fields. If claim is not successful
  // another thread may have claimed the item in the meantime. Therefore loop
  // until an item is successfully claimed or we are reasonably sure there
  // are no unclaimed items left.
  while (TRUE) {
    $conditions = array(
      ':name' => $this->name,
      ':now' => time(),
    );
    $item = db_query_range('SELECT * FROM {queue} q
        WHERE name = :name AND ((expire = 0) OR (:now > expire))
        ORDER BY created, item_id
        ASC', 0, 1, $conditions)
      ->fetchObject();
    if ($item) {
      $item = new $this->class_queue_item((int) $item->created, unserialize($item->data), (int) $item->expire, (int) $item->item_id);

      // Try to update the item. Only one thread can succeed in UPDATEing the
      // same row. We cannot rely on REQUEST_TIME because items might be
      // claimed by a single consumer which runs longer than 1 second. If we
      // continue to use REQUEST_TIME instead of the current time(), we steal
      // time from the lease, and will tend to reset items before the lease
      // should really expire.
      $update = db_update('queue')
        ->fields(array(
        'expire' => time() + $lease_time,
      ))
        ->condition('item_id', $item->item_id);

      // If there are affected rows, this update succeeded.
      if ($update
        ->execute()) {
        return $item;
      }
    }
    else {

      // No items currently available to claim.
      return FALSE;
    }
  }
}