Skip to content
Snippets Groups Projects
Commit f4d5155f authored by Prasad's avatar Prasad
Browse files

Merge branch 'fix_issue_1572' into 'master'

#1572 avoid running cronjob tasks if they are already running. Change status...

See merge request !1256
parents c96065c6 65cca7d8
No related branches found
No related tags found
1 merge request!1256#1572 avoid running cronjob tasks if they are already running. Change status...
......@@ -24,4 +24,5 @@ $languageStrings = array(
'LBL_RUNNING' => 'Running',
'LBL_ACTIVE' => 'Active',
'LBL_INACTIVE' => 'In Active',
'LBL_ERROR' => 'ERROR',
);
......@@ -136,6 +136,8 @@ class Settings_CronTasks_Record_Model extends Settings_Vtiger_Record_Model {
$fieldLabel = 'LBL_RUNNING';
} else if ($fieldValue === Settings_CronTasks_Record_Model::$STATUS_ENABLED) {
$fieldLabel = 'LBL_ACTIVE';
} else if ($fieldValue === Vtiger_Cron::$STATUS_ERROR) {
$fieldLabel = 'LBL_ERROR';
} else {
$fieldLabel = 'LBL_INACTIVE';
}
......
......@@ -61,6 +61,11 @@ if(vtigercron_detect_run_in_cli() || (isset($_SESSION["authenticated_user_id"])
try {
$cronTask->setBulkMode(true);
if ($cronTask->isRunning()) {
echo sprintf("[INFO] %s - is already running. Skipping execution.\n", $cronTask->getName());
continue;
}
// Not ready to run yet?
if (!$cronTask->isRunnable()) {
echo sprintf("[INFO] %s - not ready to run as the time to run again is not completed\n", $cronTask->getName());
......@@ -85,6 +90,7 @@ if(vtigercron_detect_run_in_cli() || (isset($_SESSION["authenticated_user_id"])
echo "\n".sprintf('[CRON],"%s",%s,%s,"%s","%s",[ENDS]',$cronRunId,$site_URL,$cronTask->getName(),date('Y-m-d H:i:s',$cronTask->getLastStart()),date('Y-m-d H:i:s',$cronTask->getLastEnd()))."\n";
} catch (Exception $e) {
$cronTask->updateStatus(Vtiger_Cron::$STATUS_ERROR);
echo sprintf("[ERROR]: %s - cron task execution throwed exception.\n", $cronTask->getName());
echo $e->getMessage();
echo "\n";
......
......@@ -23,6 +23,7 @@ class Vtiger_Cron {
static $STATUS_ENABLED = 1;
static $STATUS_RUNNING = 2;
static $STATUS_COMPLETED = 3;
static $STATUS_ERROR = 4;
protected $data;
protected $bulkMode = false;
......@@ -201,6 +202,7 @@ class Vtiger_Cron {
case self::$STATUS_DISABLED:
case self::$STATUS_ENABLED:
case self::$STATUS_RUNNING:
case self::$STATUS_ERROR:
break;
default:
throw new Exception('Invalid status');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment