5 * Contains \Drupal\Console\Command\Queue\DebugCommand.
8 namespace Drupal\Console\Command\Queue;
10 use Drupal\Console\Core\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;
20 * @package Drupal\Console\Command\Queue
22 class RunCommand extends Command
25 * @var QueueWorkerManagerInterface
27 protected $queueWorker;
33 protected $queueFactory;
36 * DebugCommand constructor.
38 * @param QueueWorkerManagerInterface $queueWorker
39 * @param QueueFactory $queue
41 public function __construct(
42 QueueWorkerManagerInterface $queueWorker,
43 QueueFactory $queueFactory
45 $this->queueWorker = $queueWorker;
46 $this->queueFactory = $queueFactory;
47 parent::__construct();
53 protected function configure()
56 ->setName('queue:run')
57 ->setDescription($this->trans('commands.queue.run.description'))
60 InputArgument::OPTIONAL,
61 $this->trans('commands.queue.run.arguments.name')
62 )->setAliases(['qr']);
68 protected function execute(InputInterface $input, OutputInterface $output)
70 $name = $input->getArgument('name');
73 $this->getIo()->error(
74 $this->trans('commands.queue.run.messages.missing-name')
81 $worker = $this->queueWorker->createInstance($name);
82 $queue = $this->queueFactory->get($name);
83 } catch (\Exception $e) {
84 $this->getIo()->error(
86 $this->trans('commands.queue.run.messages.invalid-name'),
94 $start = microtime(true);
95 $result = $this->runQueue($queue, $worker);
96 $time = microtime(true) - $start;
98 if (!empty($result['error'])) {
99 $this->getIo()->error(
101 $this->trans('commands.queue.run.messages.failed'),
110 $this->getIo()->success(
112 $this->trans('commands.queue.run.success'),
124 * @param \Drupal\Core\Queue\QueueInterface $queue
125 * @param \Drupal\Core\Queue\QueueWorkerInterface $worker
129 private function runQueue($queue, $worker)
131 $result['count'] = 0;
132 $result['total'] = $queue->numberOfItems();
133 while ($item = $queue->claimItem()) {
135 $worker->processItem($item->data);
136 $queue->deleteItem($item);
138 } catch (SuspendQueueException $e) {
139 $queue->releaseItem($item);
140 $result['error'] = $e;