示例#1
0
 /**
  * listQueues.
  */
 private function listQueues()
 {
     $queues = [];
     foreach ($this->queueWorker->getDefinitions() as $name => $info) {
         $queues[$name] = $this->formatQueue($name);
     }
     return $queues;
 }
示例#2
0
 /**
  * Processes cron queues.
  */
 protected function processQueues()
 {
     // Grab the defined cron queues.
     foreach ($this->queueManager->getDefinitions() as $queue_name => $info) {
         if (isset($info['cron'])) {
             // Make sure every queue exists. There is no harm in trying to recreate
             // an existing queue.
             $this->queueFactory->get($queue_name)->createQueue();
             $queue_worker = $this->queueManager->createInstance($queue_name);
             $end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15);
             $queue = $this->queueFactory->get($queue_name);
             $lease_time = isset($info['cron']['time']) ?: NULL;
             while (time() < $end && ($item = $queue->claimItem($lease_time))) {
                 try {
                     $queue_worker->processItem($item->data);
                     $queue->deleteItem($item);
                 } catch (RequeueException $e) {
                     // The worker requested the task be immediately requeued.
                     $queue->releaseItem($item);
                 } 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);
                     watchdog_exception('cron', $e);
                     // Skip to the next queue.
                     continue 2;
                 } 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.
                     watchdog_exception('cron', $e);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     /** @var QueueInterface $queue */
     $queue = $this->queueFactory->get('manual_node_publisher');
     /** @var QueueWorkerInterface $queue_worker */
     $queue_worker = $this->queueManager->createInstance('manual_node_publisher');
     while ($item = $queue->claimItem()) {
         try {
             $queue_worker->processItem($item->data);
             $queue->deleteItem($item);
         } 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);
             break;
         } 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.
             watchdog_exception('npq', $e);
         }
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $name = $input->getArgument('name');
     if (!$name) {
         $io->error($this->trans('commands.queue.run.messages.missing-name'));
         return 1;
     }
     try {
         $worker = $this->queueWorker->createInstance($name);
     } catch (\Exception $e) {
         $io->error(sprintf($this->trans('commands.queue.run.messages.invalid-name'), $name));
         return 1;
     }
     $start = microtime(true);
     $result = $this->runQueue($worker);
     $time = microtime(true) - $start;
     if (!empty($result['error'])) {
         $io->error(sprintf($this->trans('commands.queue.run.messages.failed'), $name, $result['error']));
         return 1;
     }
     $io->success(sprintf($this->trans('commands.queue.run.success'), $name, $result['count'], $result['total'], round($time, 2)));
     return 0;
 }