$value) { if (module_hook($key, 'cron')) { if ($debug) { $message = "Calling ${key}_cron()..."; watchdog('cron_debug', $message, WATCHDOG_NOTICE); } module_invoke($key, 'cron'); } } // Write a message to the logs if the user wants us to do so. if (variable_get('poormanscron_log_cron_runs', 1) == 1) { $seconds = time() - $time_t; $message = "Cron run completed. Time elapsed: $seconds " . "seconds"; watchdog('cron', $message, WATCHDOG_NOTICE); } // Update the time of the last poormanscron run (this one). variable_set('poormanscron_lastrun', time()); // Delete any messages added during the cron run (and existing prior // messages). drupal_get_messages(); // Restore any prior messages. if (isset($saved_messages)) { foreach ($saved_messages as $type => $types_messages) { foreach ($types_messages as $message) { drupal_set_message($message, $type); } } } } // End of _poormanscron_run_crontabs() /** * Implementation of hook_exit(). * * Checks if poormanscron needs to be run. If this is the case, it invokes * the cron hooks of all enabled modules, which are executed after * all HTML is returned to the browser. So the user who kicks off the cron * jobs should not notice any delay. */ function poormanscron_exit() { // // Uncomment these for testing // //variable_set('poormanscron_lastrun', (time()-601)); //variable_set('poormanscron_lastrun', 0); exit(); // Calculate when the next poormanscron run is due. $lastrun = variable_get('poormanscron_lastrun', 0); $interval = variable_get('poormanscron_interval', 60); $nextrun = $lastrun + 60 * $interval; $time_t = time(); // If the configured time has passed, start the next poormanscron run. if ($time_t > $nextrun) { if (!_poormanscron_get_lock()) { return(null); } if (!_poormanscron_check_parallel($time_t)) { return(null); } if (variable_get('poormanscron_log_cron_runs', 1) == 1) { $message = "Starting cron run... ($time_t > $nextrun)"; watchdog('cron', $message, WATCHDOG_NOTICE); } // // If this cron run fails to complete, wait a few minutes before retrying. // $retry_interval = variable_get('poormanscron_retry_interval', 10); $lastrun = variable_get('poormanscron_lastrun', 0) + 60 * $retry_interval; variable_set('poormanscron_lastrun', $lastrun); // // Everything is good, go run our crontabs! // _poormanscron_run_crontabs($time_t); } } // End of poormanscron_exit() /** * Implementation of hook_settings(). */ function poormanscron_settings() { $cron_runs_interval_description = t('Minimum number of minutes between cron runs. Cron will actually execute during the first page request after the interval has elapsed.'); $retry_interval_description = t('The number of minutes to wait after a cron run error before retrying.'); $log_cron_runs_description = t('If you want to log successful cron runs to the Drupal watchdog, say Yes here. If those messages annoy you, disable them by selecting No.'); $output = ''; $group = form_textfield(t('Cron runs interval'), 'poormanscron_interval', variable_get('poormanscron_interval', 60), 5, 10, $cron_runs_interval_description); $group .= form_textfield(t('Retry interval'), 'poormanscron_retry_interval', variable_get('poormanscron_retry_interval', 10), 3, 10, $retry_interval_description); $output .= form_group(t('Time intervals'), $group); $group = form_select(t('Log successful cron runs'), 'poormanscron_log_cron_runs', variable_get('poormanscron_log_cron_runs', 1), array('1' => t('Yes'), '0' => t('No')), $log_cron_runs_description); $output .= form_group(t('Logging'), $group); return $output; } ?>