function hook_queue_info

You are here

8 system.api.php hook_queue_info()

Declare queues holding items that need to be run periodically.

While there can be only one hook_cron() process running at the same time, there can be any number of processes defined here running. Because of this, long running tasks are much better suited for this API. Items queued in hook_cron() might be processed in the same cron run if there are not many items in the queue, otherwise it might take several requests, which can be run in parallel.

You can create queues, add items to them, claim them, etc without declaring the queue in this hook if you want, however, you need to take care of processing the items in the queue in that case.

Return value

An associative array where the key is the queue name and the value is again an associative array. Possible keys are:

  • 'worker callback': A PHP callable to call that is an implementation of callback_queue_worker().
  • 'cron': (optional) 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.

    If the cron key is not defined, the queue will not be processed by cron, and must be processed by other means.

See also

hook_cron()

hook_queue_info_alter()

Related topics

3 functions implement hook_queue_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_queue_info in core/modules/aggregator/aggregator.module
Implements hook_queue_info().
cron_queue_test_queue_info in core/modules/system/tests/modules/cron_queue_test/cron_queue_test.module
locale_queue_info in core/modules/locale/locale.module
Implements hook_queue_info().
1 invocation of hook_queue_info()
Cron::run in core/lib/Drupal/Core/Cron.php
Executes a cron run.

File

core/modules/system/system.api.php, line 128
Hooks provided by Drupal core and the System module.

Code

function hook_queue_info() {
  $queues['aggregator_feeds'] = array(
    'title' => t('Aggregator refresh'),
    'worker callback' => array('Drupal\my_module\MyClass', 'aggregatorRefresh'),
    
    // Only needed if this queue should be processed by cron.
    'cron' => array(
      'time' => 60,
    ),
  );
  return $queues;
}