NEW Show also shceduled task never finished in scheduled task widget

This commit is contained in:
Laurent Destailleur
2022-09-05 12:27:06 +02:00
parent 9a4a740d4b
commit 33ad0de37e
7 changed files with 49 additions and 14 deletions

View File

@@ -86,7 +86,7 @@ class box_scheduled_jobs extends ModeleBoxes
$result = 0; $result = 0;
$sql = "SELECT t.rowid, t.datelastrun, t.datenextrun, t.datestart,"; $sql = "SELECT t.rowid, t.datelastrun, t.datenextrun, t.datestart,";
$sql .= " t.label, t.status, t.test, t.lastresult"; $sql .= " t.label, t.status, t.test, t.lastresult, t.processing";
$sql .= " FROM " . MAIN_DB_PREFIX . "cronjob as t"; $sql .= " FROM " . MAIN_DB_PREFIX . "cronjob as t";
$sql .= " WHERE status <> ".$cronstatic::STATUS_DISABLED; $sql .= " WHERE status <> ".$cronstatic::STATUS_DISABLED;
$sql .= " AND entity IN (0, ".$conf->entity.")"; $sql .= " AND entity IN (0, ".$conf->entity.")";
@@ -95,6 +95,7 @@ class box_scheduled_jobs extends ModeleBoxes
$result = $this->db->query($sql); $result = $this->db->query($sql);
$line = 0; $line = 0;
$nbjobsinerror = 0; $nbjobsinerror = 0;
$nbjobsnotfinished = 0;
if ($result) { if ($result) {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
@@ -109,6 +110,7 @@ class box_scheduled_jobs extends ModeleBoxes
} }
if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $objp->maxrun))) { if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $objp->maxrun))) {
// Save in cronstatic the job if it is a job to run in future
$cronstatic->id = $objp->rowid; $cronstatic->id = $objp->rowid;
$cronstatic->ref = $objp->rowid; $cronstatic->ref = $objp->rowid;
$cronstatic->label = $langs->trans($objp->label); $cronstatic->label = $langs->trans($objp->label);
@@ -117,6 +119,7 @@ class box_scheduled_jobs extends ModeleBoxes
$cronstatic->datelastrun = $this->db->jdate($objp->datelastrun); $cronstatic->datelastrun = $this->db->jdate($objp->datelastrun);
} }
if ($line == 0) { if ($line == 0) {
// Save the first line in loop that is the most recent executed job (due to the sort on datelastrun DESC)
$resultarray[$line] = array( $resultarray[$line] = array(
$langs->trans("LastExecutedScheduledJob"), $langs->trans("LastExecutedScheduledJob"),
$cronstatic->getNomUrl(1), $cronstatic->getNomUrl(1),
@@ -127,6 +130,9 @@ class box_scheduled_jobs extends ModeleBoxes
$line++; $line++;
} }
if ($objp->processing && $this->db->jdate($objp->datelastrun) < (dol_now() - 3600 * 24)) {
$nbjobsnotfinished++;
}
if (!empty($objp->lastresult)) { if (!empty($objp->lastresult)) {
$nbjobsinerror++; $nbjobsinerror++;
} }
@@ -168,9 +174,19 @@ class box_scheduled_jobs extends ModeleBoxes
'td' => 'class="tdoverflowmax300" colspan="3"', 'td' => 'class="tdoverflowmax300" colspan="3"',
'text' => $langs->trans("NumberScheduledJobError") 'text' => $langs->trans("NumberScheduledJobError")
); );
$textnoformat = '';
if ($nbjobsnotfinished) {
$textnoformat .= '<a class="inline-block paddingleft paddingright marginleftonly marginrightonly minwidth25 nounderlineimp" href="'.DOL_URL_ROOT.'/cron/list.php" title="'.$langs->trans("NumberScheduledJobNeverFinished").'"><div class="center badge badge-warning nounderlineimp"><i class="fa fa-exclamation-triangle"></i> '.$nbjobsnotfinished.'</div></a>';
}
if ($nbjobsinerror) {
$textnoformat .= '<a class="inline-block paddingleft paddingright marginleftonly marginrightonly minwidth25 nounderlineimp" href="'.DOL_URL_ROOT.'/cron/list.php?search_lastresult='.urlencode('<>0').'" title="'.$langs->trans("NumberScheduledJobError").'"><div class="badge badge-danger nounderlineimp"><i class="fa fa-exclamation-triangle"></i> '.$nbjobsinerror.'</div></a>';
}
if (empty($nbjobsnotfinished) && empty($nbjobsinerror)) {
$textnoformat .= '<a class="inline-block paddingleft paddingright marginleftonly marginrightonly minwidth25 nounderlineimp" href="'.DOL_URL_ROOT.'/cron/list.php"><div class="center badge badge-status4 nounderline">0</div></a>';
}
$this->info_box_contents[$line][] = array( $this->info_box_contents[$line][] = array(
'td' => 'class="center"', 'td' => 'class="center"',
'textnoformat' => ($nbjobsinerror ? '<a href="'.DOL_URL_ROOT.'/cron/list.php?search_lastresult='.urlencode('<>0').'"><div class="badge badge-danger"><i class="fa fa-exclamation-triangle"></i> '.$nbjobsinerror.'</div></a>' : '<a href="'.DOL_URL_ROOT.'/cron/list.php"><div class="center badge-status4">0</div></a>') 'textnoformat' => $textnoformat
); );
} else { } else {
$this->info_box_contents[0][0] = array( $this->info_box_contents[0][0] = array(

View File

@@ -523,7 +523,11 @@ function run_sql($sqlfile, $silent = 1, $entity = '', $usesavepoint = 1, $handle
}); });
}); });
</script>'; </script>';
print ' - <a class="trforrunsqlshowhide'.$keyforsql.'" href="#">'.$langs->trans("ShowHideDetails").'</a>'; if (count($arraysql)) {
print ' - <a class="trforrunsqlshowhide'.$keyforsql.'" href="#" title="'.($langs->trans("ShowHideTheNRequests", count($arraysql))).'">'.$langs->trans("ShowHideDetails").'</a>';
} else {
print ' - <span class="opacitymedium">'.$langs->trans("ScriptIsEmpty").'</span>';
}
//} //}
print '</td></tr>'."\n"; print '</td></tr>'."\n";

View File

@@ -64,6 +64,7 @@ $search_status = (GETPOSTISSET('search_status') ?GETPOST('search_status', 'int')
$search_label = GETPOST("search_label", 'alpha'); $search_label = GETPOST("search_label", 'alpha');
$search_module_name = GETPOST("search_module_name", 'alpha'); $search_module_name = GETPOST("search_module_name", 'alpha');
$search_lastresult = GETPOST("search_lastresult", "alphawithlgt"); $search_lastresult = GETPOST("search_lastresult", "alphawithlgt");
$search_processing = GETPOST("search_processing", "int");
$securitykey = GETPOST('securitykey', 'alpha'); $securitykey = GETPOST('securitykey', 'alpha');
$outputdir = $conf->cron->dir_output; $outputdir = $conf->cron->dir_output;
@@ -277,6 +278,9 @@ if ($search_status >= 0 && $search_status < 2 && $search_status != '') {
if ($search_lastresult != '') { if ($search_lastresult != '') {
$sql .= natural_search("t.lastresult", $search_lastresult, 1); $sql .= natural_search("t.lastresult", $search_lastresult, 1);
} }
if (GETPOSTISSET('search_processing')) {
$sql .= " AND t.processing = ".((int) $search_processing);
}
//Manage filter //Manage filter
if (is_array($filter) && count($filter) > 0) { if (is_array($filter) && count($filter) > 0) {
foreach ($filter as $key => $value) { foreach ($filter as $key => $value) {

View File

@@ -2308,3 +2308,5 @@ UsePassword=Use a password
UseOauth=Use a OAUTH token UseOauth=Use a OAUTH token
Images=Images Images=Images
MaxNumberOfImagesInGetPost=Max number of images allowed in a HTML field submitted in a form MaxNumberOfImagesInGetPost=Max number of images allowed in a HTML field submitted in a form
ScriptIsEmpty=The script is empty
ShowHideTheNRequests=Show/hide the %s SQL request(s)

View File

@@ -93,3 +93,4 @@ JobXMustBeEnabled=Job %s must be enabled
LastExecutedScheduledJob=Last executed scheduled job LastExecutedScheduledJob=Last executed scheduled job
NextScheduledJobExecute=Next scheduled job to execute NextScheduledJobExecute=Next scheduled job to execute
NumberScheduledJobError=Number of scheduled jobs in error NumberScheduledJobError=Number of scheduled jobs in error
NumberScheduledJobNeverFinished=Number of scheduled jobs never finished

View File

@@ -821,6 +821,9 @@ textarea.centpercent {
.nounderline { .nounderline {
text-decoration: none; text-decoration: none;
} }
.nounderlineimp {
text-decoration: none !important;
}
.nopadding { .nopadding {
padding: 0; padding: 0;
} }
@@ -1532,6 +1535,7 @@ table[summary="list_of_modules"] .fa-cog {
.clearboth { clear:both; } .clearboth { clear:both; }
.hideobject { display: none; } .hideobject { display: none; }
.minwidth25 { min-width: 25px; }
.minwidth50 { min-width: 50px; } .minwidth50 { min-width: 50px; }
.minwidth75 { min-width: 75px; } .minwidth75 { min-width: 75px; }
/* rule for not too small screen only */ /* rule for not too small screen only */

View File

@@ -973,6 +973,9 @@ textarea.centpercent {
.nounderline { .nounderline {
text-decoration: none; text-decoration: none;
} }
.nounderlineimp {
text-decoration: none !important;
}
.nopadding { .nopadding {
padding: 0; padding: 0;
} }
@@ -1623,6 +1626,7 @@ tr.nobottom td {
.clearboth { clear:both; } .clearboth { clear:both; }
.hideobject { display: none; } .hideobject { display: none; }
.minwidth25 { min-width: 25px; }
.minwidth50 { min-width: 50px; } .minwidth50 { min-width: 50px; }
.minwidth75 { min-width: 75px; } .minwidth75 { min-width: 75px; }
/* rule for not too small screen only */ /* rule for not too small screen only */