Skip to content
Snippets Groups Projects
Commit 6bf61c67 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

FIX #6586 Introduce processing status

parent 41063e7c
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ class Cronjob extends CommonObject ...@@ -55,6 +55,7 @@ class Cronjob extends CommonObject
var $unitfrequency; var $unitfrequency;
var $frequency; var $frequency;
var $status; var $status;
var $processing;
var $fk_user_author; var $fk_user_author;
var $fk_user_mod; var $fk_user_mod;
var $nbrun; var $nbrun;
...@@ -287,6 +288,7 @@ class Cronjob extends CommonObject ...@@ -287,6 +288,7 @@ class Cronjob extends CommonObject
$sql.= " t.unitfrequency,"; $sql.= " t.unitfrequency,";
$sql.= " t.frequency,"; $sql.= " t.frequency,";
$sql.= " t.status,"; $sql.= " t.status,";
$sql.= " t.processing,";
$sql.= " t.fk_user_author,"; $sql.= " t.fk_user_author,";
$sql.= " t.fk_user_mod,"; $sql.= " t.fk_user_mod,";
$sql.= " t.note,"; $sql.= " t.note,";
...@@ -330,6 +332,7 @@ class Cronjob extends CommonObject ...@@ -330,6 +332,7 @@ class Cronjob extends CommonObject
$this->unitfrequency = $obj->unitfrequency; $this->unitfrequency = $obj->unitfrequency;
$this->frequency = $obj->frequency; $this->frequency = $obj->frequency;
$this->status = $obj->status; $this->status = $obj->status;
$this->processing = $obj->processing;
$this->fk_user_author = $obj->fk_user_author; $this->fk_user_author = $obj->fk_user_author;
$this->fk_user_mod = $obj->fk_user_mod; $this->fk_user_mod = $obj->fk_user_mod;
$this->note = $obj->note; $this->note = $obj->note;
...@@ -352,15 +355,16 @@ class Cronjob extends CommonObject ...@@ -352,15 +355,16 @@ class Cronjob extends CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param string $sortorder sort order * @param string $sortorder sort order
* @param string $sortfield sort field * @param string $sortfield sort field
* @param int $limit limit page * @param int $limit limit page
* @param int $offset page * @param int $offset page
* @param int $status display active or not * @param int $status display active or not
* @param array $filter filter output * @param array $filter filter output
* @return int <0 if KO, >0 if OK * @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; global $langs;
...@@ -391,6 +395,7 @@ class Cronjob extends CommonObject ...@@ -391,6 +395,7 @@ class Cronjob extends CommonObject
$sql.= " t.unitfrequency,"; $sql.= " t.unitfrequency,";
$sql.= " t.frequency,"; $sql.= " t.frequency,";
$sql.= " t.status,"; $sql.= " t.status,";
$sql.= " t.processing,";
$sql.= " t.fk_user_author,"; $sql.= " t.fk_user_author,";
$sql.= " t.fk_user_mod,"; $sql.= " t.fk_user_mod,";
$sql.= " t.note,"; $sql.= " t.note,";
...@@ -399,6 +404,7 @@ class Cronjob extends CommonObject ...@@ -399,6 +404,7 @@ class Cronjob extends CommonObject
$sql.= " t.test"; $sql.= " t.test";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql.= " WHERE 1 = 1"; $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 >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1');
if ($status == 2) $sql.= " AND t.status = 2"; if ($status == 2) $sql.= " AND t.status = 2";
//Manage filter //Manage filter
...@@ -463,6 +469,7 @@ class Cronjob extends CommonObject ...@@ -463,6 +469,7 @@ class Cronjob extends CommonObject
$line->unitfrequency = $obj->unitfrequency; $line->unitfrequency = $obj->unitfrequency;
$line->frequency = $obj->frequency; $line->frequency = $obj->frequency;
$line->status = $obj->status; $line->status = $obj->status;
$line->processing = $obj->processing;
$line->fk_user_author = $obj->fk_user_author; $line->fk_user_author = $obj->fk_user_author;
$line->fk_user_mod = $obj->fk_user_mod; $line->fk_user_mod = $obj->fk_user_mod;
$line->note = $obj->note; $line->note = $obj->note;
...@@ -520,9 +527,11 @@ class Cronjob extends CommonObject ...@@ -520,9 +527,11 @@ class Cronjob extends CommonObject
if (isset($this->status)) $this->status=trim($this->status); if (isset($this->status)) $this->status=trim($this->status);
if (isset($this->note)) $this->note=trim($this->note); if (isset($this->note)) $this->note=trim($this->note);
if (isset($this->nbrun)) $this->nbrun=trim($this->nbrun); 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->libname)) $this->libname = trim($this->libname);
if (isset($this->test)) $this->test = trim($this->test); 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 // Check parameters
// Put here code to add a control on parameters values // Put here code to add a control on parameters values
...@@ -588,6 +597,7 @@ class Cronjob extends CommonObject ...@@ -588,6 +597,7 @@ class Cronjob extends CommonObject
$sql.= " unitfrequency=".(isset($this->unitfrequency)?$this->unitfrequency:"null").","; $sql.= " unitfrequency=".(isset($this->unitfrequency)?$this->unitfrequency:"null").",";
$sql.= " frequency=".(isset($this->frequency)?$this->frequency:"null").","; $sql.= " frequency=".(isset($this->frequency)?$this->frequency:"null").",";
$sql.= " status=".(isset($this->status)?$this->status:"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.= " fk_user_mod=".$user->id.",";
$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
$sql.= " nbrun=".((isset($this->nbrun) && $this->nbrun >0)?$this->nbrun:"null").","; $sql.= " nbrun=".((isset($this->nbrun) && $this->nbrun >0)?$this->nbrun:"null").",";
...@@ -786,7 +796,8 @@ class Cronjob extends CommonObject ...@@ -786,7 +796,8 @@ class Cronjob extends CommonObject
$this->lastresult=''; $this->lastresult='';
$this->unitfrequency=''; $this->unitfrequency='';
$this->frequency=''; $this->frequency='';
$this->status=''; $this->status=0;
$this->processing=0;
$this->fk_user_author=''; $this->fk_user_author='';
$this->fk_user_mod=''; $this->fk_user_mod='';
$this->note=''; $this->note='';
...@@ -898,6 +909,7 @@ class Cronjob extends CommonObject ...@@ -898,6 +909,7 @@ class Cronjob extends CommonObject
$this->datelastresult=null; $this->datelastresult=null;
$this->lastoutput=''; $this->lastoutput='';
$this->lastresult=''; $this->lastresult='';
$this->processing = 1; // To know job was started
$this->nbrun=$this->nbrun + 1; $this->nbrun=$this->nbrun + 1;
$result = $this->update($user); // This include begin/commit $result = $this->update($user); // This include begin/commit
if ($result<0) { if ($result<0) {
...@@ -1099,6 +1111,7 @@ class Cronjob extends CommonObject ...@@ -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)"); 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->datelastresult=dol_now();
$this->processing=0;
$result = $this->update($user); // This include begin/commit $result = $this->update($user); // This include begin/commit
if ($result < 0) if ($result < 0)
{ {
......
...@@ -125,6 +125,9 @@ INSERT INTO llx_const (name, entity, value, type, visible, note) VALUES ('USER_A ...@@ -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 ref varchar(16);
ALTER TABLE llx_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL; 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 create table llx_payment_various
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
...@@ -144,3 +147,6 @@ create table llx_payment_various ...@@ -144,3 +147,6 @@ create table llx_payment_various
fk_user_author integer, fk_user_author integer,
fk_user_modif integer fk_user_modif integer
)ENGINE=innodb; )ENGINE=innodb;
...@@ -46,6 +46,7 @@ CREATE TABLE llx_cronjob ...@@ -46,6 +46,7 @@ CREATE TABLE llx_cronjob
nbrun integer, -- nb of run complete (failed or not) 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 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 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', test varchar(255) DEFAULT '1',
fk_user_author integer DEFAULT NULL, fk_user_author integer DEFAULT NULL,
fk_user_mod integer DEFAULT NULL, fk_user_mod integer DEFAULT NULL,
......
...@@ -111,7 +111,7 @@ if (! empty($id)) ...@@ -111,7 +111,7 @@ if (! empty($id))
$filter['t.rowid']=$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) if ($result<0)
{ {
echo "Error: ".$cronjob->error; echo "Error: ".$cronjob->error;
......
...@@ -128,7 +128,7 @@ if (! empty($id)) { ...@@ -128,7 +128,7 @@ if (! empty($id)) {
$filter['t.rowid']=$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) if ($result<0)
{ {
echo "Error: ".$object->error; echo "Error: ".$object->error;
...@@ -136,7 +136,7 @@ if ($result<0) ...@@ -136,7 +136,7 @@ if ($result<0)
exit(-1); 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 // current date
$now=dol_now(); $now=dol_now();
......
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