5 * Contains \Drupal\Console\Command\Queue\DebugCommand.
8 namespace Drupal\Console\Command\Queue;
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Core\Queue\QueueWorkerManagerInterface;
15 use Drupal\Core\Queue\QueueFactory;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
22 * @package Drupal\Console\Command\Queue
24 class RunCommand extends Command
29 * @var QueueWorkerManagerInterface
31 protected $queueWorker;
40 * DebugCommand constructor.
42 * @param QueueWorkerManagerInterface $queueWorker
43 * @param QueueFactory $queue
45 public function __construct(
46 QueueWorkerManagerInterface $queueWorker,
49 $this->queueWorker = $queueWorker;
50 $this->queue = $queue;
51 parent::__construct();
57 protected function configure()
60 ->setName('queue:run')
61 ->setDescription($this->trans('commands.queue.run.description'))
64 InputArgument::OPTIONAL,
65 $this->trans('commands.queue.run.arguments.name')
72 protected function execute(InputInterface $input, OutputInterface $output)
74 $io = new DrupalStyle($input, $output);
75 $name = $input->getArgument('name');
79 $this->trans('commands.queue.run.messages.missing-name')
86 $worker = $this->queueWorker->createInstance($name);
87 } catch (\Exception $e) {
90 $this->trans('commands.queue.run.messages.invalid-name'),
98 $start = microtime(true);
99 $result = $this->runQueue($worker);
100 $time = microtime(true) - $start;
102 if (!empty($result['error'])) {
105 $this->trans('commands.queue.run.messages.failed'),
116 $this->trans('commands.queue.run.success'),
132 private function runQueue($worker)
134 $result['count'] = 0;
135 $result['total'] = $this->queue->numberOfItems();
136 while ($item = $this->queue->claimItem()) {
138 $worker->processItem($item->data);
139 $this->queue->deleteItem($item);
141 } catch (SuspendQueueException $e) {
142 $this->queue->releaseItem($item);
143 $result['error'] = $e;