diff options
Diffstat (limited to 'apis/cron.inc.php')
-rw-r--r-- | apis/cron.inc.php | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/apis/cron.inc.php b/apis/cron.inc.php index 75d7f132..03b6201f 100644 --- a/apis/cron.inc.php +++ b/apis/cron.inc.php @@ -14,15 +14,15 @@ define('CRON_KEY_STATUS', 'cron.key.status'); define('CRON_KEY_BLOCKED', 'cron.key.blocked'); // Crash report mode - used by system crontab entry -if (($report = Request::get('crashreport', false, 'string'))) { +if (($report = Request::get('crashreport', false, 'string')) !== false) { $list = Property::getList(CRON_KEY_STATUS); if (empty($list)) { error_log('Cron crash report triggered but no cronjob marked active.'); exit(0); } $str = array(); - foreach ($list as $item) { - Property::removeFromList(CRON_KEY_STATUS, $item); + foreach ($list as $subkey => $item) { + Property::removeFromListByKey(CRON_KEY_STATUS, $subkey); $entry = explode('|', $item, 2); if (count($entry) !== 2) continue; @@ -35,7 +35,7 @@ if (($report = Request::get('crashreport', false, 'string'))) { if (empty($str)) { $str = 'an unknown module'; } - $message = 'Conjob failed. No reply by ' . implode(', ', $str); + $message = 'Cronjob failed. No reply by ' . implode(', ', $str); $details = ''; if (is_readable($report)) { $details = file_get_contents($report); @@ -62,9 +62,22 @@ function getJobStatus($id) } // Hooks by other modules -function handleModule($file) +function handleModule(Hook $hook): void { - include_once $file; + global $cron_log_text; + $cron_log_text = ''; + include_once $hook->file; + if (!empty($cron_log_text)) { + EventLog::info('CronJob ' . $hook->moduleId . ' finished.', $cron_log_text); + } +} + +$cron_log_text = ''; +function cron_log($text) +{ + // XXX: Enable this code for debugging -- make this configurable some day + //global $cron_log_text; + //$cron_log_text .= $text . "\n"; } $blocked = Property::getList(CRON_KEY_BLOCKED); @@ -75,13 +88,13 @@ foreach (Hook::load('cron') as $hook) { $runtime = (time() - $status['start']); if ($runtime < 0) { // Clock skew - Property::removeFromList(CRON_KEY_STATUS, $status['string']); + Property::removeFromListByVal(CRON_KEY_STATUS, $status['string']); } elseif ($runtime < 900) { // Allow up to 15 minutes for a job to complete before we complain... continue; } else { // Consider job crashed - Property::removeFromList(CRON_KEY_STATUS, $status['string']); + Property::removeFromListByVal(CRON_KEY_STATUS, $status['string']); EventLog::failure('Cronjob for module ' . $hook->moduleId . ' seems to be stuck or has crashed.'); continue; } @@ -93,10 +106,10 @@ foreach (Hook::load('cron') as $hook) { $value = $hook->moduleId . '|' . time(); Property::addToList(CRON_KEY_STATUS, $value, 30); try { - handleModule($hook->file); + handleModule($hook); } catch (Exception $e) { // Logging EventLog::failure('Cronjob for module ' . $hook->moduleId . ' has crashed. Check the php or web server error log.', $e->getMessage()); } - Property::removeFromList(CRON_KEY_STATUS, $value); + Property::removeFromListByVal(CRON_KEY_STATUS, $value); } |