From 76e3d53c1f55564e3d01d6a3b5f3d2d5550ee858 Mon Sep 17 00:00:00 2001 From: Jennifer Hodgdon Date: Tue, 2 Dec 2014 10:26:32 -0800 Subject: Issue #2208649 by joachim, er.pushpinderrana: document queue worker callback --- modules/system/system.api.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'modules/system') diff --git a/modules/system/system.api.php b/modules/system/system.api.php index 362e32263..0af6156a4 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -606,8 +606,8 @@ function hook_cron() { * @return * An associative array where the key is the queue name and the value is * again an associative array. Possible keys are: - * - 'worker callback': The name of the function to call. It will be called - * with one argument, the item created via DrupalQueue::createItem(). + * - 'worker callback': A PHP callable to call that is an implementation of + * callback_queue_worker(). * - 'time': (optional) How much time Drupal should spend on calling this * worker in seconds. Defaults to 15. * - 'skip on cron': (optional) Set to TRUE to avoid being processed during @@ -643,6 +643,28 @@ function hook_cron_queue_info_alter(&$queues) { $queues['aggregator_feeds']['time'] = 90; } +/** + * Work on a single queue item. + * + * Callback for hook_queue_info(). + * + * @param $queue_item_data + * The data that was passed to DrupalQueue::createItem() when the item was + * queued. + * + * @throws \Exception + * The worker callback may throw an exception to indicate there was a problem. + * The cron process will log the exception, and leave the item in the queue to + * be processed again later. + * + * @see drupal_cron_run() + */ +function callback_queue_worker($queue_item_data) { + $node = node_load($queue_item_data); + $node->title = 'Updated title'; + $node->save(); +} + /** * Allows modules to declare their own Form API element types and specify their * default values. -- cgit v1.2.3