class QueueWorker

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Annotation/QueueWorker.php \Drupal\Core\Annotation\QueueWorker
  2. 10 core/lib/Drupal/Core/Queue/Attribute/QueueWorker.php \Drupal\Core\Queue\Attribute\QueueWorker
  3. 10 core/lib/Drupal/Core/Annotation/QueueWorker.php \Drupal\Core\Annotation\QueueWorker
  4. 11.x core/lib/Drupal/Core/Queue/Attribute/QueueWorker.php \Drupal\Core\Queue\Attribute\QueueWorker
  5. 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

9 classes are annotated with QueueWorker
AggregatorRefresh in core/modules/aggregator/src/Plugin/QueueWorker/AggregatorRefresh.php
Updates a feed's items.
CronQueueTestBrokenQueue in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestBrokenQueue.php
Plugin annotation @QueueWorker( id = "cron_queue_test_broken_queue", title = @Translation("Broken queue test"), cron = {"time" = 60} )
CronQueueTestDatabaseDelayException in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestDatabaseDelayException.php
A queue worker for testing cron exception handling.
CronQueueTestException in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestException.php
Plugin annotation @QueueWorker( id = "cron_queue_test_exception", title = @Translation("Exception test"), cron = {"time" = 1} )
CronQueueTestLeaseTime in core/modules/system/tests/modules/cron_queue_test/src/Plugin/QueueWorker/CronQueueTestLeaseTime.php
Plugin annotation @QueueWorker( id = "cron_queue_test_lease_time", title = @Translation("Lease time test"), cron = {"time" = 100} )

... See full list

File

core/lib/Drupal/Core/Annotation/QueueWorker.php, line 38

Namespace

Drupal\Core\Annotation
View source
class QueueWorker extends Plugin {
    
    /**
     * The plugin ID.
     *
     * @var string
     */
    public $id;
    
    /**
     * The human-readable title of the plugin.
     *
     * @var \Drupal\Core\Annotation\Translation
     *
     * @ingroup plugin_translatable
     */
    public $title;
    
    /**
     * An optional associative array of settings for cron.
     *
     * @var array
     *   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().
     *
     * @see \Drupal\Core\Queue\QueueWorkerManager::processDefinition()
     */
    public $cron;

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Plugin::$definition protected property The plugin definition read from the class annotation. 1
Plugin::get public function Gets the value of an annotation. Overrides AnnotationInterface::get 6
Plugin::getClass public function Gets the class of the annotated class. Overrides AnnotationInterface::getClass 1
Plugin::getId public function Gets the unique ID for this annotated class. Overrides AnnotationInterface::getId
Plugin::getProvider public function Gets the name of the provider of the annotated class. Overrides AnnotationInterface::getProvider 1
Plugin::parse protected function Parses an annotation into its definition.
Plugin::setClass public function Sets the class of the annotated class. Overrides AnnotationInterface::setClass 1
Plugin::setProvider public function Sets the name of the provider of the annotated class. Overrides AnnotationInterface::setProvider
Plugin::__construct public function Constructs a Plugin object. 3
QueueWorker::$cron public property An optional associative array of settings for cron.
QueueWorker::$id public property The plugin ID.
QueueWorker::$title public property The human-readable title of the plugin.

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