Debug the cron module
This commit is contained in:
parent
a973c91c24
commit
a4edd90320
@ -317,7 +317,7 @@ if (($action=="create") || ($action=="edit"))
|
||||
print "</tr>\n";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronHourStart')."</td><td>";
|
||||
print $langs->trans('CronDtStart')."</td><td>";
|
||||
if(!empty($object->datestart))
|
||||
{
|
||||
$form->select_date($object->datestart,'datestart',1,1,'',"cronform");
|
||||
@ -518,15 +518,22 @@ else
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronHourStart')."</td><td>";
|
||||
if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print $langs->trans('CronDtStart')."</td><td>";
|
||||
if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');}
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronDtEnd')."</td><td>";
|
||||
if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronDtNextLaunch');
|
||||
print ' ('.$langs->trans('CronFrom').')';
|
||||
print "</td><td>";
|
||||
if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhoursec');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print "<tr><td>";
|
||||
print $langs->trans('CronPriority')."</td>";
|
||||
print "<td>".$object->priority;
|
||||
@ -591,23 +598,17 @@ else
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td width="30%">';
|
||||
print $langs->trans('CronDtLastLaunch')."</td><td>";
|
||||
if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronDtNextLaunch');
|
||||
print ' ('.$langs->trans('CronFrom').')';
|
||||
print "</td><td>";
|
||||
if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhoursec');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('CronDtLastResult')."</td><td>";
|
||||
if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhourtext');} else {print $langs->trans('CronNone');}
|
||||
if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhoursec');} else {print $langs->trans('CronNone');}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td>';
|
||||
|
||||
@ -521,9 +521,6 @@ class Cronjob extends CommonObject
|
||||
|
||||
// Check parameters
|
||||
// Put here code to add a control on parameters values
|
||||
if (empty($this->status)) {
|
||||
$this->dateend=dol_now();
|
||||
}
|
||||
if (dol_strlen($this->datestart)==0) {
|
||||
$this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronDtStart'));
|
||||
$error++;
|
||||
@ -830,7 +827,9 @@ class Cronjob extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
* Run a job
|
||||
* Run a job.
|
||||
* Once job is finished, status and nb of of run is updated.
|
||||
* This function does not plan the next run. This is done by function ->reprogram_jobs
|
||||
*
|
||||
* @param string $userlogin User login
|
||||
* @return int <0 if KO, >0 if OK
|
||||
@ -843,7 +842,8 @@ class Cronjob extends CommonObject
|
||||
|
||||
$langs->load('cron');
|
||||
|
||||
if (empty($userlogin)) {
|
||||
if (empty($userlogin))
|
||||
{
|
||||
$this->error="User login is mandatory";
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
@ -891,7 +891,7 @@ class Cronjob extends CommonObject
|
||||
$this->datelastrun=$now;
|
||||
$this->lastoutput='';
|
||||
$this->lastresult='';
|
||||
$this->nbrun=$this->nbrun+1;
|
||||
$this->nbrun=$this->nbrun + 1;
|
||||
$result = $this->update($user);
|
||||
if ($result<0) {
|
||||
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
|
||||
@ -1055,23 +1055,28 @@ class Cronjob extends CommonObject
|
||||
/**
|
||||
* Reprogram a job
|
||||
*
|
||||
* @param string $userlogin User login
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*
|
||||
* @param string $userlogin User login
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function reprogram_jobs($userlogin)
|
||||
{
|
||||
dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG);
|
||||
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
|
||||
$user=new User($this->db);
|
||||
$result=$user->fetch('',$userlogin);
|
||||
if ($result<0) {
|
||||
if ($result<0)
|
||||
{
|
||||
$this->error="User Error:".$user->error;
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}else {
|
||||
if (empty($user->id)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($user->id))
|
||||
{
|
||||
$this->error=" User user login:".$userlogin." do not exists";
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
@ -1080,17 +1085,41 @@ class Cronjob extends CommonObject
|
||||
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ", LOG_DEBUG);
|
||||
|
||||
if (empty($this->datenextrun)) {
|
||||
$this->datenextrun=dol_now()+$this->frequency;
|
||||
} else {
|
||||
if ($this->datenextrun<dol_now()) {
|
||||
$this->datenextrun=dol_now()+$this->frequency;
|
||||
} else {
|
||||
$this->datenextrun=$this->datenextrun+$this->frequency;
|
||||
|
||||
if (empty($this->datenextrun))
|
||||
{
|
||||
$this->datenextrun = $now + $this->frequency;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->datenextrun < $now && $this->frequency > 0)
|
||||
{
|
||||
// Loop until date is after future
|
||||
while ($this->datenextrun < $now)
|
||||
{
|
||||
$this->datenextrun += $this->frequency;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//$this->datenextrun=$this->datenextrun+$this->frequency;
|
||||
}
|
||||
}
|
||||
|
||||
// Archive job
|
||||
if ($this->autodelete == 2)
|
||||
{
|
||||
if (($this->maxrun > 0 && ($this->nbrun >= $this->maxrun))
|
||||
|| ($this->dateend && ($this->datenextrun > $this->dateend)))
|
||||
{
|
||||
$this->status = 2;
|
||||
dol_syslog(get_class($this)."::reprogram_jobs Job must be set to archived", LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->update($user);
|
||||
if ($result<0) {
|
||||
if ($result<0)
|
||||
{
|
||||
dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -173,14 +173,14 @@ print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans("ID"),$_SERVER["PHP_SELF"],"t.rowid","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronLabel"),$_SERVER["PHP_SELF"],"t.label","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronTask"),'','',"",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtStart"),$_SERVER["PHP_SELF"],"t.datestart","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtEnd"),$_SERVER["PHP_SELF"],"t.dateend","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtLastLaunch"),$_SERVER["PHP_SELF"],"t.datelastrun","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtNextLaunch"),$_SERVER["PHP_SELF"],"t.datenextrun","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtStart"),$_SERVER["PHP_SELF"],"t.datestart","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtEnd"),$_SERVER["PHP_SELF"],"t.dateend","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtNextLaunch"),$_SERVER["PHP_SELF"],"t.datenextrun","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronFrequency"),'',"","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronNbRun"),$_SERVER["PHP_SELF"],"t.nbrun","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronMaxRun"),$_SERVER["PHP_SELF"],"t.maxrun","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronLastResult"),$_SERVER["PHP_SELF"],"t.lastresult","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronMaxRun"),$_SERVER["PHP_SELF"],"t.maxrun","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronNbRun"),$_SERVER["PHP_SELF"],"t.nbrun","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronDtLastLaunch"),$_SERVER["PHP_SELF"],"t.datelastrun","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronLastResult"),$_SERVER["PHP_SELF"],"t.lastresult","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("CronLastOutput"),$_SERVER["PHP_SELF"],"t.lastoutput","",$param,'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"t.status","",$param,'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre('');
|
||||
@ -259,19 +259,15 @@ if ($num > 0)
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print '<td class="center">';
|
||||
if(!empty($line->datestart)) {print dol_print_date($line->datestart,'dayhour');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print '<td class="center">';
|
||||
if(!empty($line->dateend)) {print dol_print_date($line->dateend,'dayhour');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhour');}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print '<td class="center">';
|
||||
if(!empty($line->datenextrun)) {print dol_print_date($line->datenextrun,'dayhour');}
|
||||
print '</td>';
|
||||
|
||||
@ -282,15 +278,19 @@ if ($num > 0)
|
||||
if($line->unitfrequency == "604800") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Weeks');
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
if (!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print '<td align="right">';
|
||||
if (!empty($line->maxrun)) {print $line->maxrun;}
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print '<td align="right">';
|
||||
if (!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center">';
|
||||
if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhour');}
|
||||
print '</td>';
|
||||
|
||||
print '<td class="center">';
|
||||
if(!empty($line->lastresult)) {print dol_trunc($line->lastresult);}
|
||||
print '</td>';
|
||||
|
||||
|
||||
@ -33,18 +33,18 @@ CREATE TABLE llx_cronjob
|
||||
md5params varchar(32),
|
||||
module_name varchar(255),
|
||||
priority integer DEFAULT 0,
|
||||
datelastrun datetime, -- date last run and when should be next
|
||||
datelastrun datetime, -- date last run start (see datelastresult for end with a result)
|
||||
datenextrun datetime, -- job will be run if current date higher that this date
|
||||
datestart datetime, -- before this date no jobs will be run
|
||||
dateend datetime, -- after this date, no more jobs will be run
|
||||
datelastresult datetime,
|
||||
datelastresult datetime, -- date last run end
|
||||
lastresult text,
|
||||
lastoutput text,
|
||||
unitfrequency integer NOT NULL DEFAULT 0,
|
||||
frequency integer NOT NULL DEFAULT 0,
|
||||
maxrun integer NOT NULL DEFAULT 0, -- set this to 1 for a job queued for on run only
|
||||
nbrun integer, -- nb of run complete (failed or not)
|
||||
autodelete integer DEFAULT 0, -- 1=Job must be deleted once finished, 2=Job must be archived once finished (archive = status 2)
|
||||
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
|
||||
fk_user_author integer DEFAULT NULL,
|
||||
fk_user_mod integer DEFAULT NULL,
|
||||
|
||||
@ -36,8 +36,8 @@ CronInfo=Scheduled job module allow to execute job that have been planned
|
||||
CronWaitingJobs=Waiting jobs
|
||||
CronTask=Job
|
||||
CronNone=None
|
||||
CronDtStart=Start date
|
||||
CronDtEnd=End date
|
||||
CronDtStart=Not before
|
||||
CronDtEnd=Not after
|
||||
CronDtNextLaunch=Next execution
|
||||
CronDtLastLaunch=Last execution
|
||||
CronFrequency=Frequency
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
|
||||
* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
|
||||
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
|
||||
* Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -147,7 +147,7 @@ if(is_array($object->lines) && (count($object->lines)>0))
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// we re-program the next execution and stores the last execution time for this job
|
||||
// we re-program the next execution and stores the last execution time for this job
|
||||
$result=$cronjob->reprogram_jobs($userlogin);
|
||||
if ($result<0) {
|
||||
echo "Error:".$cronjob->error;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user