class InstantQueueRunner

Provides an instant queue runner that processes items in kernel.destruct.

Hierarchy

Expanded class hierarchy of InstantQueueRunner

1 string reference to 'InstantQueueRunner'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses InstantQueueRunner
Drupal\Core\Queue\InstantQueueRunnerInterface in core/core.services.yml
Drupal\Core\Queue\InstantQueueRunner

File

core/lib/Drupal/Core/Queue/InstantQueueRunner.php, line 14

Namespace

Drupal\Core\Queue
View source
class InstantQueueRunner implements InstantQueueRunnerInterface, DestructableInterface {
  use QueueProcessTrait;
  
  /**
   * An array of integers keyed by queue name.
   *
   * Tracks the number of items registered per queue during the request.
   */
  protected array $queues = [];
  public function __construct(protected QueueFactory $queueFactory, protected QueueWorkerManagerInterface $queueManager, #[Autowire(service: 'logger.channel.queue')] protected LoggerChannelInterface $logger, #[Autowire(param: 'instant_queue.config')] protected array $config) {
  }
  
  /**
   * {@inheritdoc}
   */
  public function registerQueue(string $queue_name) : void {
    $this->queues[$queue_name] = ($this->queues[$queue_name] ?? 0) + 1;
  }
  
  /**
   * {@inheritdoc}
   */
  public function destruct() : void {
    foreach ($this->queues as $queue_name => $count) {
      $queue = $this->queueFactory
        ->get($queue_name);
      // Make sure every queue exists. There is no harm in trying to recreate
      // an existing queue.
      $queue->createQueue();
      $worker = $this->queueManager
        ->createInstance($queue_name);
      $count = min($this->config['maximumItems'], $count);
      while ($count) {
        $count--;
        try {
          $claimed = $this->processItem($queue, $worker);
          if (!$claimed) {
            break;

          }
        } catch (SuspendQueueException) {
          break;

        }
      }
    }
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.