From d9135600c92ecd7d747a386cf612c092e2d3e943 Mon Sep 17 00:00:00 2001 From: catch Date: Tue, 17 Apr 2012 12:07:50 +0900 Subject: [PATCH] Issue #1509996 by jhedstrom: Added Convert hook_cron_queue_info() to hook_queue_info(). --- core/includes/common.inc | 22 ++++++++++------- core/modules/aggregator/aggregator.module | 9 ++++--- core/modules/system/system.api.php | 29 ++++++++++++++++------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index 5ff6167e5d6..32f5a7eed96 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5305,8 +5305,8 @@ function drupal_cron_run() { $return = FALSE; // Grab the defined cron queues. - $queues = module_invoke_all('cron_queue_info'); - drupal_alter('cron_queue_info', $queues); + $queues = module_invoke_all('queue_info'); + drupal_alter('queue_info', $queues); // Try to acquire cron lock. if (!lock_acquire('cron', 240.0)) { @@ -5317,7 +5317,9 @@ function drupal_cron_run() { // Make sure every queue exists. There is no harm in trying to recreate an // existing queue. foreach ($queues as $queue_name => $info) { - queue($queue_name)->createQueue(); + if (isset($info['cron'])) { + queue($queue_name)->createQueue(); + } } // Register shutdown callback. drupal_register_shutdown_function('drupal_cron_cleanup'); @@ -5345,12 +5347,14 @@ function drupal_cron_run() { } foreach ($queues as $queue_name => $info) { - $function = $info['worker callback']; - $end = time() + (isset($info['time']) ? $info['time'] : 15); - $queue = queue($queue_name); - while (time() < $end && ($item = $queue->claimItem())) { - $function($item->data); - $queue->deleteItem($item); + if (isset($info['cron'])) { + $function = $info['worker callback']; + $end = time() + (isset($info['cron']['time']) ? $info['cron']['time'] : 15); + $queue = queue($queue_name); + while (time() < $end && ($item = $queue->claimItem())) { + $function($item->data); + $queue->deleteItem($item); + } } } // Restore the user. diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 9a266baf579..caac2790d7c 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -331,12 +331,15 @@ function aggregator_cron() { } /** - * Implements hook_cron_queue_info(). + * Implements hook_queue_info(). */ -function aggregator_cron_queue_info() { +function aggregator_queue_info() { $queues['aggregator_feeds'] = array( + 'title' => t('Aggregator refresh'), 'worker callback' => 'aggregator_refresh', - 'time' => 60, + 'cron' => array( + 'time' => 60, + ), ); return $queues; } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 17df44407bf..cfc510216fa 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -120,7 +120,7 @@ function hook_admin_paths_alter(&$paths) { * Long-running tasks and tasks that could time out, such as retrieving remote * data, sending email, and intensive file tasks, should use the queue API * instead of executing the tasks directly. To do this, first define one or - * more queues via hook_cron_queue_info(). Then, add items that need to be + * more queues via hook_queue_info(). Then, add items that need to be * processed to the defined queues. */ function hook_cron() { @@ -154,22 +154,33 @@ function hook_cron() { * 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 * 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 * Drupal\Core\Queue\QueueInterface::createItem() in hook_cron(). - * - 'time': (optional) How much time Drupal should spend on calling this - * worker in seconds. Defaults to 15. + * - '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 hook_cron() - * @see hook_cron_queue_info_alter() + * @see hook_queue_info_alter() */ -function hook_cron_queue_info() { +function hook_queue_info() { $queues['aggregator_feeds'] = array( + 'title' => t('Aggregator refresh'), 'worker callback' => 'aggregator_refresh', - 'time' => 60, + // Only needed if this queue should be processed by cron. + 'cron' => array( + 'time' => 60, + ), ); return $queues; } @@ -183,13 +194,13 @@ function hook_cron_queue_info() { * @param array $queues * An array of cron queue information. * - * @see hook_cron_queue_info() + * @see hook_queue_info() * @see drupal_cron_run() */ -function hook_cron_queue_info_alter(&$queues) { +function hook_queue_info_alter(&$queues) { // This site has many feeds so let's spend 90 seconds on each cron run // updating feeds instead of the default 60. - $queues['aggregator_feeds']['time'] = 90; + $queues['aggregator_feeds']['cron']['time'] = 90; } /**