diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-07-02 15:31:10 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-07-02 15:31:10 +0000 |
commit | c0ca1e4563cae04ae8d5f56d1487eb4a3a7a711a (patch) | |
tree | 472f2b0728e45076199eca1abd4f2f9c3d625d2d | |
parent | 27519ac981dcec7b8ac7cc35be2de11bc726d7a6 (diff) | |
download | brdo-c0ca1e4563cae04ae8d5f56d1487eb4a3a7a711a.tar.gz brdo-c0ca1e4563cae04ae8d5f56d1487eb4a3a7a711a.tar.bz2 |
- Patch #805702 by Berdir: cron should use locking framework.
-rw-r--r-- | includes/common.inc | 27 | ||||
-rw-r--r-- | modules/system/system.install | 7 |
2 files changed, 13 insertions, 21 deletions
diff --git a/includes/common.inc b/includes/common.inc index 3cd3fa149..99464d2d3 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4594,27 +4594,15 @@ function drupal_cron_run() { // Try to allocate enough time to run all the hook_cron implementations. drupal_set_time_limit(240); - // 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) { - // Either cron has been running for more than an hour or the semaphore - // was not reset due to a database error. - watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR); - - // Release cron semaphore - variable_del('cron_semaphore'); - } - else { - // Cron is still running normally. - watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); - } + // Try to acquire cron lock. + if (!lock_acquire('cron', 240.0)) { + // Cron is still running normally. + watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); } else { // Make sure every queue exists. There is no harm in trying to recreate an @@ -4625,9 +4613,6 @@ function drupal_cron_run() { // Register shutdown callback drupal_register_shutdown_function('drupal_cron_cleanup'); - // Lock cron semaphore - variable_set('cron_semaphore', REQUEST_TIME); - // Iterate through the modules calling their cron handlers (if any): module_invoke_all('cron'); @@ -4635,8 +4620,8 @@ function drupal_cron_run() { variable_set('cron_last', REQUEST_TIME); watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE); - // Release cron semaphore - variable_del('cron_semaphore'); + // Release cron lock. + lock_release('cron'); // Return TRUE so other functions can check if it did run successfully $return = TRUE; diff --git a/modules/system/system.install b/modules/system/system.install index b6bf9675c..114240ed8 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -2576,6 +2576,13 @@ function system_update_7057() { } /** + * Remove cron semaphore variable. + */ +function system_update_7058() { + variable_del('cron_semaphore'); +} + +/** * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */ |