class QueueWorker

Same name in this branch
  1. 10 core/lib/Drupal/Core/Annotation/QueueWorker.php \Drupal\Core\Annotation\QueueWorker
Same name in other branches
  1. 9 core/lib/Drupal/Core/Annotation/QueueWorker.php \Drupal\Core\Annotation\QueueWorker
  2. 8.9.x core/lib/Drupal/Core/Annotation/QueueWorker.php \Drupal\Core\Annotation\QueueWorker
  3. 11.x core/lib/Drupal/Core/Queue/Attribute/QueueWorker.php \Drupal\Core\Queue\Attribute\QueueWorker
  4. 11.x core/lib/Drupal/Core/Annotation/QueueWorker.php \Drupal\Core\Annotation\QueueWorker

Declare a worker class for processing a queue item.

Worker plugins are used by some queues for processing the individual items in the queue. In that case, the ID of the worker plugin needs to match the machine name of a queue, so that you can retrieve the queue back end by calling \Drupal\Core\Queue\QueueFactory::get($plugin_id).

\Drupal\Core\Cron::processQueues() processes queues that use workers; they can also be processed outside of the cron process.

Some queues do not use worker plugins: you can create queues, add items to them, claim them, etc. without using a QueueWorker plugin. However, you will need to take care of processing the items in the queue in that case. You can look at \Drupal\Core\Cron::processQueues() for an example of how to process a queue that uses workers, and adapt it to your queue.

Plugin Namespace: Plugin\QueueWorker

For a working example, see \Drupal\locale\Plugin\QueueWorker\LocaleTranslation.

Hierarchy

Expanded class hierarchy of QueueWorker

See also

\Drupal\Core\Queue\QueueWorkerInterface

\Drupal\Core\Queue\QueueWorkerBase

\Drupal\Core\Queue\QueueWorkerManager

Plugin API

Related topics

10 files declare their use of QueueWorker
CronQueueTestDatabaseDelayException.php in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestDatabaseDelayException.php
CronQueueTestDeriverQueue.php in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestDeriverQueue.php
CronQueueTestException.php in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestException.php
CronQueueTestLeaseTime.php in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestLeaseTime.php
CronQueueTestMemoryDelayException.php in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestMemoryDelayException.php

... See full list

File

core/lib/Drupal/Core/Queue/Attribute/QueueWorker.php, line 37

Namespace

Drupal\Core\Queue\Attribute
View source
class QueueWorker extends Plugin {
    
    /**
     * @param string $id
     *   The plugin ID.
     * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $title
     *   The human-readable title of the plugin.
     * @param array|null $cron
     *   (optional) An associative array of settings for cron. The array has one
     *   key, time, which is set to the time Drupal cron should spend on calling
     *   this worker in seconds. The default is set in
     *   \Drupal\Core\Queue\QueueWorkerManager::processDefinition().
     * @param class-string|null $deriver
     *   (optional) The deriver class.
     */
    public function __construct(string $id, ?TranslatableMarkup $title = NULL, ?array $cron = NULL, ?string $deriver = NULL) {
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AttributeBase::$class protected property The class used for this attribute class.
AttributeBase::$provider protected property The provider of the attribute class.
AttributeBase::get public function Gets the value of an attribute. Overrides AttributeInterface::get 6
AttributeBase::getClass public function Gets the class of the attribute class. Overrides AttributeInterface::getClass 1
AttributeBase::getId public function Gets the unique ID for this attribute class. Overrides AttributeInterface::getId
AttributeBase::getProvider public function Gets the name of the provider of the attribute class. Overrides AttributeInterface::getProvider
AttributeBase::setClass public function Sets the class of the attributed class. Overrides AttributeInterface::setClass 1
AttributeBase::setProvider public function Sets the name of the provider of the attribute class. Overrides AttributeInterface::setProvider
QueueWorker::__construct public function Overrides Plugin::__construct

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