public function Queue7::run

8.0.x Queue7.php public Queue7::run($name, $time_limit = 0)
7.x Queue7.php public Queue7::run($name, $time_limit = 0)
master Queue7.php public Queue7::run($name, $time_limit = 0)

Runs a given queue.

Parameters

string $name: The name of the queue to run.

int $time_limit: The maximum number of seconds that the queue can run. By default the queue will be run as long as possible.

Return value

int The number of items successfully processed from the queue.

Overrides QueueInterface::run

File

lib/Drush/Queue/Queue7.php, line 42

Namespace

Drush\Queue

Class

Queue7

Code

public function run($name, $time_limit = 0) {
  $info = $this->getInfo($name);
  $function = $info['worker callback'];
  $end = time() + $time_limit;
  $queue = $this->getQueue($name);
  $count = 0;

  while ((!$time_limit || time() < $end) && ($item = $queue->claimItem())) {
    try {
      drush_log(dt('Processing item @id from @name queue.', array('@name' => $name, 'id' => $item->item_id)), LogLevel::INFO);
      $function($item->data);
      $queue->deleteItem($item);
      $count++;
    }
    catch (\Exception $e) {
      // In case of exception log it and leave the item in the queue
      // to be processed again later.
      drush_set_error('DRUSH_QUEUE_EXCEPTION', $e->getMessage());
    }
  }

  return $count;
}