diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 59a3d02538630fb549626a54be17716ccc7a7185..2f9ad12a57fc03968ab475df5b027fbb60a56a09 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -55,6 +55,7 @@ class Cronjob extends CommonObject var $unitfrequency; var $frequency; var $status; + var $processing; var $fk_user_author; var $fk_user_mod; var $nbrun; @@ -287,6 +288,7 @@ class Cronjob extends CommonObject $sql.= " t.unitfrequency,"; $sql.= " t.frequency,"; $sql.= " t.status,"; + $sql.= " t.processing,"; $sql.= " t.fk_user_author,"; $sql.= " t.fk_user_mod,"; $sql.= " t.note,"; @@ -330,6 +332,7 @@ class Cronjob extends CommonObject $this->unitfrequency = $obj->unitfrequency; $this->frequency = $obj->frequency; $this->status = $obj->status; + $this->processing = $obj->processing; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_mod = $obj->fk_user_mod; $this->note = $obj->note; @@ -352,15 +355,16 @@ class Cronjob extends CommonObject /** * Load object in memory from the database * - * @param string $sortorder sort order - * @param string $sortfield sort field - * @param int $limit limit page - * @param int $offset page - * @param int $status display active or not - * @param array $filter filter output - * @return int <0 if KO, >0 if OK + * @param string $sortorder sort order + * @param string $sortfield sort field + * @param int $limit limit page + * @param int $offset page + * @param int $status display active or not + * @param array $filter filter output + * @param int $processing Processing or not + * @return int <0 if KO, >0 if OK */ - function fetch_all($sortorder='DESC', $sortfield='t.rowid', $limit=0, $offset=0, $status=1, $filter='') + function fetch_all($sortorder='DESC', $sortfield='t.rowid', $limit=0, $offset=0, $status=1, $filter='', $processing=-1) { global $langs; @@ -391,6 +395,7 @@ class Cronjob extends CommonObject $sql.= " t.unitfrequency,"; $sql.= " t.frequency,"; $sql.= " t.status,"; + $sql.= " t.processing,"; $sql.= " t.fk_user_author,"; $sql.= " t.fk_user_mod,"; $sql.= " t.note,"; @@ -399,6 +404,7 @@ class Cronjob extends CommonObject $sql.= " t.test"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $sql.= " WHERE 1 = 1"; + if ($processing >= 0) $sql.= " AND t.processing = ".(empty($processing)?'0':'1'); if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1'); if ($status == 2) $sql.= " AND t.status = 2"; //Manage filter @@ -463,6 +469,7 @@ class Cronjob extends CommonObject $line->unitfrequency = $obj->unitfrequency; $line->frequency = $obj->frequency; $line->status = $obj->status; + $line->processing = $obj->processing; $line->fk_user_author = $obj->fk_user_author; $line->fk_user_mod = $obj->fk_user_mod; $line->note = $obj->note; @@ -520,9 +527,11 @@ class Cronjob extends CommonObject if (isset($this->status)) $this->status=trim($this->status); if (isset($this->note)) $this->note=trim($this->note); if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun); - if (empty($this->maxrun)) $this->maxrun=0; if (isset($this->libname)) $this->libname = trim($this->libname); if (isset($this->test)) $this->test = trim($this->test); + + if (empty($this->maxrun)) $this->maxrun=0; + if (empty($this->processing)) $this->processing=0; // Check parameters // Put here code to add a control on parameters values @@ -588,6 +597,7 @@ class Cronjob extends CommonObject $sql.= " unitfrequency=".(isset($this->unitfrequency)?$this->unitfrequency:"null").","; $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.= " fk_user_mod=".$user->id.","; $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; $sql.= " nbrun=".((isset($this->nbrun) && $this->nbrun >0)?$this->nbrun:"null").","; @@ -786,7 +796,8 @@ class Cronjob extends CommonObject $this->lastresult=''; $this->unitfrequency=''; $this->frequency=''; - $this->status=''; + $this->status=0; + $this->processing=0; $this->fk_user_author=''; $this->fk_user_mod=''; $this->note=''; @@ -898,6 +909,7 @@ class Cronjob extends CommonObject $this->datelastresult=null; $this->lastoutput=''; $this->lastresult=''; + $this->processing = 1; // To know job was started $this->nbrun=$this->nbrun + 1; $result = $this->update($user); // This include begin/commit if ($result<0) { @@ -1099,6 +1111,7 @@ class Cronjob extends CommonObject dol_syslog(get_class($this)."::run_jobs now we update job to track it is finished (with success or error)"); $this->datelastresult=dol_now(); + $this->processing=0; $result = $this->update($user); // This include begin/commit if ($result < 0) { diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 25145dc7cfe3608267a427a133c780a7e176474f..6e098e4f59d0751e863957693bb566867b83e248 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -125,6 +125,9 @@ INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USER_A ALTER TABLE llx_chargesociales ADD COLUMN ref varchar(16); ALTER TABLE llx_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL; +ALTER TABLE llx_cronjob ADD COLUMN processing integer NOT NULL DEFAULT 0; + + create table llx_payment_various ( rowid integer AUTO_INCREMENT PRIMARY KEY, @@ -144,3 +147,6 @@ create table llx_payment_various fk_user_author integer, fk_user_modif integer )ENGINE=innodb; + + + diff --git a/htdocs/install/mysql/tables/llx_cronjob.sql b/htdocs/install/mysql/tables/llx_cronjob.sql index f9d2ac1ab7abd30486b66f18e6f031a2f347d907..96458de842049bd409ad5e9e5c3242dfbb56dac2 100644 --- a/htdocs/install/mysql/tables/llx_cronjob.sql +++ b/htdocs/install/mysql/tables/llx_cronjob.sql @@ -46,6 +46,7 @@ CREATE TABLE llx_cronjob nbrun integer, -- nb of run complete (failed or not) autodelete integer DEFAULT 0, -- 0=Job is kept unchanged once nbrun > maxrun or date > dateend, 2=Job must be archived (archive = status 2) once nbrun > maxrun or date > dateend status integer NOT NULL DEFAULT 1, -- 0=disabled, 1=enabled, 2=archived + processing integer NOT NULL DEFAULT 0, -- 1=process currently running test varchar(255) DEFAULT '1', fk_user_author integer DEFAULT NULL, fk_user_mod integer DEFAULT NULL, diff --git a/htdocs/public/cron/cron_run_jobs.php b/htdocs/public/cron/cron_run_jobs.php index fc8e15aeed68365b39db1064368a9668b3d88782..a7d3d4b3fcd0b0fad93466aa3cb766ad4430f945 100644 --- a/htdocs/public/cron/cron_run_jobs.php +++ b/htdocs/public/cron/cron_run_jobs.php @@ -111,7 +111,7 @@ if (! empty($id)) $filter['t.rowid']=$id; } -$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter); +$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter, 0); if ($result<0) { echo "Error: ".$cronjob->error; diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php index d60218fba22176bd2ee15f918dbed861e17db2e2..4360e74cae59c7f7204ddb1f9104ae586604fe86 100755 --- a/scripts/cron/cron_run_jobs.php +++ b/scripts/cron/cron_run_jobs.php @@ -128,7 +128,7 @@ if (! empty($id)) { $filter['t.rowid']=$id; } -$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter); +$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter, 0); if ($result<0) { echo "Error: ".$object->error; @@ -136,7 +136,7 @@ if ($result<0) exit(-1); } -// TODO This sequence of code must be shared with code into cron_run_jobs.php php page. +// TODO This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page. // current date $now=dol_now();