Merge pull request #1705 from MPOS/cron-check-active

[IMPROVED] Check if cron is running in PHP scripts
This commit is contained in:
Sebastian Grewe 2014-02-10 21:57:28 +01:00
commit 0cf6e38dc3
2 changed files with 19 additions and 1 deletions

View File

@ -82,7 +82,10 @@ if ($monitoring->isDisabled($cron_name)) {
// Mark cron as running for monitoring
$log->logDebug('Marking cronjob as running for monitoring');
$monitoring->setStatus($cron_name . '_starttime', 'date', time());
if (!$monitoring->startCronjob($cron_name)) {
$log->logFatal('Unable to start cronjob: ' . $monitoring->getCronError());
exit;
}
// Check if we need to halt our crons due to an outstanding upgrade
if ($setting->getValue('DB_VERSION') != DB_VERSION || $config['version'] != CONFIG_VERSION) {

View File

@ -93,6 +93,21 @@ class Monitoring extends Base {
return false;
}
/**
* Start a cronjob, mark various fields properly
* @param cron_name string Cronjob name
**/
public function startCronjob($cron_name) {
$aStatus = $this->getStatus($cron_name . '_active');
if ($aStatus['value'] == 1) {
$this->setErrorMessage('Cron is already active in database: ' . $cron_name . '_active is 1');
return false;
}
$this->setStatus($cron_name . "_active", "yesno", 1);
$this->setStatus($cron_name . '_starttime', 'date', time());
return true;
}
/**
* End cronjob with an error message
* @param cron_name string Cronjob Name