diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-10-03 00:24:19 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2006-10-03 00:24:19 +0000 |
commit | aae945c369ac9c98ab3c2c4036ff1a3453a37467 (patch) | |
tree | 0a4455a561c55ddadf8b9bc17dd13416a1434747 | |
parent | 4bd256a20fb949cd0d802d2c5ccee9374e2c87a8 (diff) | |
download | brdo-aae945c369ac9c98ab3c2c4036ff1a3453a37467.tar.gz brdo-aae945c369ac9c98ab3c2c4036ff1a3453a37467.tar.bz2 |
#70995: Prevent cron re-runs
-rw-r--r-- | includes/common.inc | 58 | ||||
-rw-r--r-- | modules/system/system.install | 5 |
2 files changed, 50 insertions, 13 deletions
diff --git a/includes/common.inc b/includes/common.inc index f2a550ad1..ef296bf9b 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1698,24 +1698,56 @@ function drupal_cron_run() { set_time_limit(240); } - // Check if the last cron run completed - if (variable_get('cron_busy', FALSE)) { - watchdog('cron', t('Last cron run did not complete.'), WATCHDOG_WARNING); + // Fetch the cron semaphore + $semaphore = variable_get('cron_semaphore', FALSE); + + if ($semaphore) { + if (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', t('Cron has been running for more than an hour and is most likely stuck.'), WATCHDOG_ERROR); + + // Release cron semaphore + variable_del('cron_semaphore'); + } + else { + // Cron is still running normally. + watchdog('cron', t('Attempting to re-run cron while it is already running.'), WATCHDOG_WARNING); + } } else { - variable_set('cron_busy', TRUE); - } + // Register shutdown callback + register_shutdown_function('drupal_cron_cleanup'); + + // Lock cron semaphore + variable_set('cron_semaphore', time()); + + // Iterate through the modules calling their cron handlers (if any): + module_invoke_all('cron'); - // Iterate through the modules calling their cron handlers (if any): - module_invoke_all('cron'); + // Record cron time + variable_set('cron_last', time()); + watchdog('cron', t('Cron run completed.'), WATCHDOG_NOTICE); - // Clean up - variable_set('cron_busy', FALSE); - variable_set('cron_last', time()); - watchdog('cron', t('Cron run completed.'), WATCHDOG_NOTICE); + // Release cron semaphore + variable_del('cron_semaphore'); - // Return TRUE so other functions can check if it did run successfully - return TRUE; + // Return TRUE so other functions can check if it did run successfully + return TRUE; + } +} + +/** + * Shutdown function for cron cleanup. + */ +function drupal_cron_cleanup() { + // See if the semaphore is still locked. + if (variable_get('cron_semaphore', FALSE)) { + watchdog('cron', t('Cron run exceeded the time limit and was aborted.'), WATCHDOG_WARNING); + + // Release cron semaphore + variable_del('cron_semaphore'); + } } /** diff --git a/modules/system/system.install b/modules/system/system.install index 4a6f988ae..758b4a17d 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -3337,6 +3337,11 @@ function system_update_1013() { return $ret; } +function system_update_1014() { + variable_del('cron_busy'); + return array(); +} + /** * @} End of "defgroup updates-4.7-to-x.x" * The next series of updates should start at 2000. |