public function Queue8::run

8.0.x Queue8.php public Queue8::run($name, $time_limit = 0)
7.x Queue8.php public Queue8::run($name, $time_limit = 0)
master Queue8.php public Queue8::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/Queue8.php, line 48

Namespace

Drush\Queue

Class

Queue8

Code

public function run($name, $time_limit = 0) {
  $worker = $this->workerManager->createInstance($name);
  $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);
      $worker->processItem($item->data);
      $queue->deleteItem($item);
      $count++;
    }
    catch (SuspendQueueException $e) {
      // If the worker indicates there is a problem with the whole queue,
      // release the item and skip to the next queue.
      $queue->releaseItem($item);
      drush_set_error('DRUSH_SUSPEND_QUEUE_EXCEPTION', $e->getMessage());
    }
    catch (\Exception $e) {
      // In case of any other kind 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;
}