claimItem

  1. drupal
    1. drupal7
Versionen
drupal7 public SystemQueue::claimItem($lease_time = 30)

Verwandte Themen

Code

modules/system/system.queue.inc, line 196

<?php
public function claimItem($lease_time = 30) {
  if (!isset($this->consumerId)) {
    $this->consumerId = db_insert('queue_consumer_id')
        ->useDefaults(array('consumer_id'))
        ->execute();
  }
  // Claim an item by updating its consumer_id and 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) {
    $item = db_query_range('SELECT data, item_id FROM {queue} q WHERE consumer_id = 0 AND name = :name ORDER BY created ASC', array(':name' => $this->name), 0, 1)->fetchObject();
    if ($item) {
      // Try to mark the item as ours. 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(
            'consumer_id' => $this->consumerId,
            'expire' => time() + $lease_time,
          ))
          ->condition('item_id', $item->item_id)
          ->condition('consumer_id', 0);
      // If there are affected rows, this update succeeded.
      if ($update->execute()) {
        $item->data = unserialize($item->data);
        return $item;
      }
    }
    else {
      // No items currently available to claim.
      return FALSE;
    }
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen