summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-09-25 15:20:12 +0000
committerDries Buytaert <dries@buytaert.net>2009-09-25 15:20:12 +0000
commit762be09fa98bf2c36cf45042c475a3bc9348e448 (patch)
tree614bff163539a82848044e96a2a5552b9c201420 /includes
parent92278086bb38a7b25272e6705c615fd9b8133f36 (diff)
downloadbrdo-762be09fa98bf2c36cf45042c475a3bc9348e448.tar.gz
brdo-762be09fa98bf2c36cf45042c475a3bc9348e448.tar.bz2
- Patch #578676 by chx | neclimdul, Crell, Dave Reid: introduce a queue for cron.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc23
1 files changed, 22 insertions, 1 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 9037365ff..06b42e0f9 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3837,6 +3837,11 @@ function drupal_cron_run() {
// Fetch the cron semaphore
$semaphore = variable_get('cron_semaphore', FALSE);
+
+ $return = FALSE;
+ // Grab the defined cron queues.
+ $queues = module_invoke_all('cron_queue_info');
+ drupal_alter('cron_queue_info', $queues);
if ($semaphore) {
if (REQUEST_TIME - $semaphore > 3600) {
@@ -3853,6 +3858,11 @@ function drupal_cron_run() {
}
}
else {
+ // Make sure every queue exists. There is no harm in trying to recreate an
+ // existing queue.
+ foreach ($queues as $queue_name => $info) {
+ DrupalQueue::get($queue_name)->createQueue();
+ }
// Register shutdown callback
register_shutdown_function('drupal_cron_cleanup');
@@ -3870,8 +3880,19 @@ function drupal_cron_run() {
variable_del('cron_semaphore');
// Return TRUE so other functions can check if it did run successfully
- return TRUE;
+ $return = TRUE;
+ }
+
+ foreach ($queues as $queue_name => $info) {
+ $function = $info['worker callback'];
+ $end = time() + (isset($info['time']) ? $info['time'] : 15);
+ $queue = DrupalQueue::get($queue_name);
+ while (time() < $end && ($item = $queue->claimItem())) {
+ $function($item->data);
+ $queue->deleteItem($item);
+ }
}
+ return $return;
}
/**