diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index a84fa3109df..200cf8a369f 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -137,6 +137,11 @@ class Cronjob extends CommonObject */ public $processing; + /** + * @var int The job current PID + */ + public $pid; + /** * @var int ID */ @@ -422,6 +427,7 @@ class Cronjob extends CommonObject $sql .= " t.frequency,"; $sql .= " t.status,"; $sql .= " t.processing,"; + $sql .= " t.pid,"; $sql .= " t.fk_user_author,"; $sql .= " t.fk_user_mod,"; $sql .= " t.note as note_private,"; @@ -470,6 +476,7 @@ class Cronjob extends CommonObject $this->frequency = $obj->frequency; $this->status = $obj->status; $this->processing = $obj->processing; + $this->pid = $obj->pid; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_mod = $obj->fk_user_mod; $this->note_private = $obj->note_private; @@ -530,6 +537,7 @@ class Cronjob extends CommonObject $sql .= " t.frequency,"; $sql .= " t.status,"; $sql .= " t.processing,"; + $sql .= " t.pid,"; $sql .= " t.fk_user_author,"; $sql .= " t.fk_user_mod,"; $sql .= " t.note as note_private,"; @@ -606,6 +614,7 @@ class Cronjob extends CommonObject $line->frequency = $obj->frequency; $line->status = $obj->status; $line->processing = $obj->processing; + $line->pid = $obj->pid; $line->fk_user_author = $obj->fk_user_author; $line->fk_user_mod = $obj->fk_user_mod; $line->note_private = $obj->note_private; @@ -708,6 +717,10 @@ class Cronjob extends CommonObject $this->processing = 0; } + if (empty($this->pid)) { + $this->pid = NULL; + } + // Check parameters // Put here code to add a control on parameters values if (dol_strlen($this->datenextrun) == 0) { @@ -773,6 +786,7 @@ class Cronjob extends CommonObject $sql .= " frequency=".(isset($this->frequency) ? $this->frequency : "null").","; $sql .= " status=".(isset($this->status) ? $this->status : "null").","; $sql .= " processing=".((isset($this->processing) && $this->processing > 0) ? $this->processing : "0").","; + $sql .= " pid=".(isset($this->pid) ? $this->pid : "null").","; $sql .= " fk_user_mod=".$user->id.","; $sql .= " note=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; $sql .= " nbrun=".((isset($this->nbrun) && $this->nbrun > 0) ? $this->nbrun : "null").","; @@ -925,6 +939,7 @@ class Cronjob extends CommonObject $this->frequency = ''; $this->status = 0; $this->processing = 0; + $this->pid = NULL; $this->fk_user_author = 0; $this->fk_user_mod = 0; $this->note_private = ''; @@ -1125,6 +1140,7 @@ class Cronjob extends CommonObject $this->lastoutput = ''; $this->lastresult = ''; $this->processing = 1; // To know job was started + $this->pid = dol_getmypid(); $this->nbrun = $this->nbrun + 1; $result = $this->update($user); // This include begin/commit if ($result < 0) { @@ -1316,6 +1332,7 @@ class Cronjob extends CommonObject $this->datelastresult = dol_now(); $this->processing = 0; + $this->pid = NULL; $result = $this->update($user); // This include begin/commit if ($result < 0) { dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);