You are here

class QueueProcessCommand in Advanced Queue 8

Class ProcessQueueCommand.

@DrupalCommand ( extension="advancedqueue", extensionType="module" )

Hierarchy

  • class \Drupal\advancedqueue\Command\QueueProcessCommand extends \Drupal\Console\Core\Command\Command

Expanded class hierarchy of QueueProcessCommand

1 string reference to 'QueueProcessCommand'
console.services.yml in ./console.services.yml
console.services.yml
1 service uses QueueProcessCommand
advancedqueue.queue_process in ./console.services.yml
Drupal\advancedqueue\Command\QueueProcessCommand

File

src/Command/QueueProcessCommand.php, line 24

Namespace

Drupal\advancedqueue\Command
View source
class QueueProcessCommand extends Command {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The queue processor.
   *
   * @var \Drupal\advancedqueue\ProcessorInterface
   */
  protected $processor;

  /**
   * Constructs a new QueueProcessCommand object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\advancedqueue\ProcessorInterface $processor
   *   The queue processor.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ProcessorInterface $processor) {
    parent::__construct();
    $this->entityTypeManager = $entity_type_manager;
    $this->processor = $processor;
  }

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this
      ->setName('advancedqueue:queue:process')
      ->addArgument('queue_id', InputArgument::REQUIRED, 'The queue ID')
      ->setDescription($this
      ->trans('commands.advancedqueue.queue.process.description'));
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output) {
    $queue_id = $input
      ->getArgument('queue_id');
    $queue_storage = $this->entityTypeManager
      ->getStorage('advancedqueue_queue');

    /** @var \Drupal\advancedqueue\Entity\QueueInterface $queue */
    $queue = $queue_storage
      ->load($queue_id);
    if (!$queue) {
      $message = $this
        ->trans('commands.advancedqueue.queue.process.messages.not-found');
      throw new \RuntimeException(sprintf($message, $queue_id));
    }
    $io = new DrupalStyle($input, $output);
    $start = microtime(TRUE);
    $num_processed = $this->processor
      ->processQueue($queue);
    $elapsed = microtime(TRUE) - $start;
    $io
      ->success(sprintf($this
      ->trans('commands.advancedqueue.queue.process.messages.finished'), $num_processed, $queue
      ->label(), round($elapsed, 2)));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueueProcessCommand::$entityTypeManager protected property The entity type manager.
QueueProcessCommand::$processor protected property The queue processor.
QueueProcessCommand::configure protected function
QueueProcessCommand::execute protected function
QueueProcessCommand::__construct public function Constructs a new QueueProcessCommand object.