class SystemQueue


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
  1. cis7 modules/system/ SystemQueue
  2. cle7 modules/system/ SystemQueue
  3. elmsmedia7 modules/system/ SystemQueue
  4. icor7 modules/system/ SystemQueue
  5. meedjum_blog7 modules/system/ SystemQueue
  6. mooc7 modules/system/ SystemQueue

Default queue implementation.


  • class SystemQueue implements \DrupalReliableQueueInterface

Expanded class hierarchy of SystemQueue


Contains filters are case sensitive
Namesort descending Modifiers Type Description
SystemQueue::$name protected property The name of the queue this instance is working with.
SystemQueue::claimItem public function Claim an item in the queue for processing. Overrides DrupalQueueInterface::claimItem
SystemQueue::createItem public function Add a queue item and store it directly to the queue. Overrides DrupalQueueInterface::createItem
SystemQueue::createQueue public function Create a queue. Overrides DrupalQueueInterface::createQueue
SystemQueue::deleteItem public function Delete a finished item from the queue. Overrides DrupalQueueInterface::deleteItem
SystemQueue::deleteQueue public function Delete a queue and every item in the queue. Overrides DrupalQueueInterface::deleteQueue
SystemQueue::numberOfItems public function Retrieve the number of items in the queue. Overrides DrupalQueueInterface::numberOfItems
SystemQueue::releaseItem public function Release an item that the worker could not process, so another worker can come in and process it before the timeout expires. Overrides DrupalQueueInterface::releaseItem
SystemQueue::__construct public function


modules/system/, line 198
Queue functionality.

View source
class SystemQueue implements DrupalReliableQueueInterface {
   * The name of the queue this instance is working with.
   * @var string
  protected $name;

  public function __construct($name) {
    $this->name = $name;

  public function createItem($data) {
    // During a Drupal 6.x to 7.x update, drupal_get_schema() does not contain
    // the queue table yet, so we cannot rely on drupal_write_record().
    $query = db_insert('queue')->fields(array(
      'name' => $this->name,
      'data' => serialize($data),
      // We cannot rely on REQUEST_TIME because many items might be created
      // by a single request which takes longer than 1 second.
      'created' => time(),
    return (bool) $query->execute();

  public function numberOfItems() {
    return db_query('SELECT COUNT(item_id) FROM {queue} WHERE name = :name', array(':name' => $this->name))->fetchField();

  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) {
      $item = db_query_range('SELECT data, item_id FROM {queue} q WHERE expire = 0 AND name = :name ORDER BY created ASC', 0, 1, array(':name' => $this->name))->fetchObject();
      if ($item) {
        // 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)->condition('expire', 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;

  public function releaseItem($item) {
    $update = db_update('queue')->fields(array(
      'expire' => 0,
    ))->condition('item_id', $item->item_id);
    return $update->execute();

  public function deleteItem($item) {
    db_delete('queue')->condition('item_id', $item->item_id)->execute();

  public function createQueue() {
    // All tasks are stored in a single database table (which is created when
    // Drupal is first installed) so there is nothing we need to do to create
    // a new queue.

  public function deleteQueue() {
    db_delete('queue')->condition('name', $this->name)->execute();

Related topics

2 string references to 'SystemQueue'
DrupalQueue::get in modules/system/
Returns the queue object for a given name.
og-7.x-1.x.database.php in sites/all/modules/ulmus/og/tests/og-7.x-1.x.database.php
Filled installation of Drupal 7.0, for test purposes.