* @QueueWorker(
* id = "my_module_image_style",
* title = @Translation("Generate image styles"),
* cron = {"time" = 60}
* )
And more specifically what is the effect of
cron = {"time" = 60}
This is actually called annotations which provide metadata about the class, and this metadata is gonna be extracted later on with our code to perform a specific logic.
in Drupal context since The QueueWorker is just another drupal plugin, so it will be handled using the Plugin Manager which will extract this information from the Annotations and use them to build some logic for example in this case:
and every drupal plugin fllow this logic:
parent:construct()
arg 4 ,wich is : (\Drupal\Core\Annotation\QueueWorker) : public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/QueueWorker', $namespaces, $module_handler, 'Drupal\Core\Queue\QueueWorkerInterface', 'Drupal\Core\Annotation\QueueWorker');
}
actually in this class peoperty doc Comment you can find a description of each annotation attribute.
<?php namespace Drupal\Core\Annotation;
use Drupal\Component\Annotation\Plugin;
class QueueWorker extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable title of the plugin.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $title;
/**
* An associative array containing the optional key:
* - time: (optional) How much time Drupal cron should spend on calling
* this worker in seconds. Defaults to 15.
*
* @var array (optional)
*/
public $cron;
}
The class comments are Annotations : What is Annotation mean ?
Annotation is a term used in computer programming to refer to documentation and comments that may be found on code logic. Annotation is typically ignored once the code is executed or compiled.
Annotations for class discovery and metadata description.
The Drupal plugin system has a set of reusable components that developers can use, override, and extend in their modules. Most of the plugins use annotations, which let classes register themselves as plugins and describe their metadata. (Annotations can also be used for other purposes, though at the moment, Drupal only uses them for the plugin system.)
A lot of frameworks use annotations too like symfony use it in many contexts like creating routes using annotations here.
For the annotation example you put in your question is for QueueWorker plugin:
cron = {"time" = 60}
the definition of cron property QueueWorker::$cron
according to QueueWorker::$cron it mean:
time: (optional) How much time Drupal cron should spend on calling this worker in seconds. Defaults to 15.
Those are called annotations, and in this context, they are used for plugin discovery.
This:
cron = {"time" = 60}
Signifies a property of the QueueWorker
annotation; specifically QueueWorker::$cron, which is:
How much time Drupal cron should spend on calling this worker in seconds. Defaults to 15.