Merge pull request #1705 from MPOS/cron-check-active
[IMPROVED] Check if cron is running in PHP scripts
This commit is contained in:
commit
0cf6e38dc3
@ -82,7 +82,10 @@ if ($monitoring->isDisabled($cron_name)) {
|
|||||||
|
|
||||||
// Mark cron as running for monitoring
|
// Mark cron as running for monitoring
|
||||||
$log->logDebug('Marking cronjob 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
|
// Check if we need to halt our crons due to an outstanding upgrade
|
||||||
if ($setting->getValue('DB_VERSION') != DB_VERSION || $config['version'] != CONFIG_VERSION) {
|
if ($setting->getValue('DB_VERSION') != DB_VERSION || $config['version'] != CONFIG_VERSION) {
|
||||||
|
|||||||
@ -93,6 +93,21 @@ class Monitoring extends Base {
|
|||||||
return false;
|
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
|
* End cronjob with an error message
|
||||||
* @param cron_name string Cronjob Name
|
* @param cron_name string Cronjob Name
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user