7.x system.queue.inc DrupalQueue::get($name, $reliable = FALSE)

Returns the queue object for a given name.

The following variables can be set by variable_set or $conf overrides:

  • queue_class_$name: the class to be used for the queue $name.
  • queue_default_class: the class to use when queue_class_$name is not defined. Defaults to SystemQueue, a reliable backend using SQL.
  • queue_default_reliable_class: the class to use when queue_class_$name is not defined and the queue_default_class is not reliable. Defaults to SystemQueue.

Parameters

$name: Arbitrary string. The name of the queue to work with.

$reliable: TRUE if the ordering of items and guaranteeing every item executes at least once is important, FALSE if scalability is the main concern.

Return value

The queue object for a given name.

13 calls to DrupalQueue::get()
aggregator_cron in modules/aggregator/aggregator.module
Implements hook_cron().
CronQueueTestCase::testCallable in modules/system/system.test
Tests worker defined as a class method callable.
CronQueueTestCase::testExceptions in modules/system/system.test
Tests that exceptions thrown by workers are handled properly.
drupal_cron_run in includes/common.inc
Executes a cron run when called.
hook_cron in modules/system/system.api.php
Perform periodic actions.

... See full list

File

modules/system/system.queue.inc, line 81
Queue functionality.

Class

DrupalQueue
Factory class for interacting with queues.

Code

public static function get($name, $reliable = FALSE) {
  static $queues;
  if (!isset($queues[$name])) {
    $class = variable_get('queue_class_' . $name, NULL);
    if (!$class) {
      $class = variable_get('queue_default_class', 'SystemQueue');
    }
    $object = new $class($name);
    if ($reliable && !$object instanceof DrupalReliableQueueInterface) {
      $class = variable_get('queue_default_reliable_class', 'SystemQueue');
      $object = new $class($name);
    }
    $queues[$name] = $object;
  }
  return $queues[$name];
}

Comments

sagar.choudhary’s picture

//we are creating the queue object for queue 'name_of_queue'
$queue = DrupalQueue::get('name_of_queue');
//now we are adding data to queue
$queue->createItem($data[$i])