count failed runs of a task

This commit is contained in:
Uwe Steinmann 2023-10-16 15:59:57 +02:00
parent bcf9b43576
commit fa429ca08f
9 changed files with 51 additions and 7 deletions

View File

@ -58,10 +58,14 @@ class SeedDMS_Controller_Cron extends SeedDMS_Controller_Common {
if($taskobj->execute($task)) { if($taskobj->execute($task)) {
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful."); add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
$arr['success'] = true; $arr['success'] = true;
$task->resetFailures();
} else { } else {
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR); add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR);
$arr['success'] = false; $arr['success'] = false;
if($task->getFailures() > 5)
$task->setDisabled(1); $task->setDisabled(1);
else
$task->incFailures();
} }
} elseif($mode == 'dryrun') { } elseif($mode == 'dryrun') {
$arr['success'] = true; $arr['success'] = true;

View File

@ -90,7 +90,7 @@ class SeedDMS_SchedulerTask {
return null; return null;
$row = $resArr[0]; $row = $resArr[0];
$task = new self($row["id"], $row['name'], $row["description"], $row["extension"], $row["task"], $row["frequency"], $row['disabled'], json_decode($row['params'], true), $row["nextrun"], $row["lastrun"]); $task = new self($row["id"], $row['name'], $row["description"], $row["extension"], $row["task"], $row["frequency"], $row['disabled'], json_decode($row['params'], true), $row["nextrun"], $row["lastrun"], $row["failures"]);
$task->setDB($db); $task->setDB($db);
return $task; return $task;
@ -106,7 +106,7 @@ class SeedDMS_SchedulerTask {
$tasks = array(); $tasks = array();
foreach($resArr as $row) { foreach($resArr as $row) {
$task = new self($row["id"], $row['name'], $row["description"], $row["extension"], $row["task"], $row["frequency"], $row['disabled'], json_decode($row['params'], true), $row["nextrun"], $row["lastrun"]); $task = new self($row["id"], $row['name'], $row["description"], $row["extension"], $row["task"], $row["frequency"], $row['disabled'], json_decode($row['params'], true), $row["nextrun"], $row["lastrun"], $row["failures"]);
$task->setDB($db); $task->setDB($db);
$tasks[] = $task; $tasks[] = $task;
} }
@ -124,7 +124,7 @@ class SeedDMS_SchedulerTask {
$tasks = array(); $tasks = array();
foreach($resArr as $row) { foreach($resArr as $row) {
$task = new self($row["id"], $row['name'], $row["description"], $row["extension"], $row["task"], $row["frequency"], $row['disabled'], json_decode($row['params'], true), $row["nextrun"], $row["lastrun"]); $task = new self($row["id"], $row['name'], $row["description"], $row["extension"], $row["task"], $row["frequency"], $row['disabled'], json_decode($row['params'], true), $row["nextrun"], $row["lastrun"], $row["failures"]);
$task->setDB($db); $task->setDB($db);
$tasks[] = $task; $tasks[] = $task;
} }
@ -132,7 +132,7 @@ class SeedDMS_SchedulerTask {
return $tasks; return $tasks;
} /* }}} */ } /* }}} */
function __construct($id, $name, $description, $extension, $task, $frequency, $disabled, $params, $nextrun, $lastrun) { function __construct($id, $name, $description, $extension, $task, $frequency, $disabled, $params, $nextrun, $lastrun, $failures) {
$this->_id = $id; $this->_id = $id;
$this->_name = $name; $this->_name = $name;
$this->_description = $description; $this->_description = $description;
@ -143,6 +143,7 @@ class SeedDMS_SchedulerTask {
$this->_params = $params; $this->_params = $params;
$this->_nextrun = $nextrun; $this->_nextrun = $nextrun;
$this->_lastrun = $lastrun; $this->_lastrun = $lastrun;
$this->_failures = $failures;
} }
public function setDB($db) { public function setDB($db) {
@ -225,6 +226,34 @@ class SeedDMS_SchedulerTask {
return $this->_lastrun; return $this->_lastrun;
} }
public function getFailures() {
return $this->_failures;
}
public function resetFailures() { /* {{{ */
$db = $this->db;
$queryStr = "UPDATE `tblSchedulerTask` SET `failures` = 0 WHERE `id` = " . $this->_id;
$res = $db->getResult($queryStr);
if (!$res)
return false;
$this->_failures = 0;
return true;
} /* }}} */
public function incFailures() { /* {{{ */
$db = $this->db;
$queryStr = "UPDATE `tblSchedulerTask` SET `failures` = ".($this->_failures+1)." WHERE `id` = " . $this->_id;
$res = $db->getResult($queryStr);
if (!$res)
return false;
$this->_failures++;
return true;
} /* }}} */
public function getDisabled() { public function getDisabled() {
return $this->_disabled; return $this->_disabled;
} }

View File

@ -1025,6 +1025,7 @@ CREATE TABLE `tblSchedulerTask` (
`params` text DEFAULT NULL, `params` text DEFAULT NULL,
`nextrun` datetime DEFAULT NULL, `nextrun` datetime DEFAULT NULL,
`lastrun` datetime DEFAULT NULL, `lastrun` datetime DEFAULT NULL,
`failures` int(11) DEFAULT '0',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -833,7 +833,8 @@ CREATE TABLE "tblSchedulerTask" (
"frequency" varchar(100) DEFAULT NULL, "frequency" varchar(100) DEFAULT NULL,
"params" TEXT DEFAULT NULL, "params" TEXT DEFAULT NULL,
"nextrun" TIMESTAMP DEFAULT NULL, "nextrun" TIMESTAMP DEFAULT NULL,
"lastrun" TIMESTAMP DEFAULT NULL "lastrun" TIMESTAMP DEFAULT NULL,
"failures" INTEGER DEFAULT '0'
) ; ) ;
-- -------------------------------------------------------- -- --------------------------------------------------------

View File

@ -842,7 +842,8 @@ CREATE TABLE `tblSchedulerTask` (
`frequency` varchar(100) DEFAULT NULL, `frequency` varchar(100) DEFAULT NULL,
`params` TEXT DEFAULT NULL, `params` TEXT DEFAULT NULL,
`nextrun` TEXT DEFAULT NULL, `nextrun` TEXT DEFAULT NULL,
`lastrun` TEXT DEFAULT NULL `lastrun` TEXT DEFAULT NULL,
`failures` INTEGER DEFAULT '0'
) ; ) ;
-- -------------------------------------------------------- -- --------------------------------------------------------

View File

@ -24,6 +24,8 @@ ALTER TABLE "tblCategory" ADD COLUMN "color" char(8) default NULL;
ALTER TABLE "tblNotify" ADD COLUMN "inherit" INTEGER NOT NULL default '0'; ALTER TABLE "tblNotify" ADD COLUMN "inherit" INTEGER NOT NULL default '0';
ALTER TABLE "tblSchedulerTask" ADD COLUMN "failures" INTEGER NOT NULL default '0';
CREATE TABLE "tblAttributeDefinitionGroups" ( CREATE TABLE "tblAttributeDefinitionGroups" (
"id" SERIAL UNIQUE, "id" SERIAL UNIQUE,
"name" varchar(100) default NULL, "name" varchar(100) default NULL,

View File

@ -70,6 +70,8 @@ ALTER TABLE `tblCategory` ADD COLUMN `color` char(8) DEFAULT NULL;
ALTER TABLE `tblNotify` ADD COLUMN `inherit` INTEGER NOT NULL DEFAULT '0'; ALTER TABLE `tblNotify` ADD COLUMN `inherit` INTEGER NOT NULL DEFAULT '0';
ALTER TABLE `tblSchedulerTask` ADD COLUMN `failures` INTEGER NOT NULL DEFAULT '0';
CREATE TABLE `tblAttributeDefinitionGroups` ( CREATE TABLE `tblAttributeDefinitionGroups` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` varchar(100) default NULL, `name` varchar(100) default NULL,

View File

@ -24,6 +24,8 @@ ALTER TABLE `tblCategory` ADD COLUMN `color` char(8) DEFAULT NULL AFTER `name`;
ALTER TABLE `tblNotify` ADD COLUMN `inherit` smallint(1) NOT NULL DEFAULT '0'; ALTER TABLE `tblNotify` ADD COLUMN `inherit` smallint(1) NOT NULL DEFAULT '0';
ALTER TABLE `tblSchedulerTask` ADD COLUMN `failures` int(11) NOT NULL DEFAULT '0';
CREATE TABLE `tblAttributeDefinitionGroups` ( CREATE TABLE `tblAttributeDefinitionGroups` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL, `name` varchar(100) DEFAULT NULL,

View File

@ -563,6 +563,8 @@ $(document).ready( function() {
echo "<i class=\"fa fa-clock-o\" title=\"".getMLText('task_next_run')."\"></i> ".getLongReadableDate(makeTsFromDate($task->getNextRun())); echo "<i class=\"fa fa-clock-o\" title=\"".getMLText('task_next_run')."\"></i> ".getLongReadableDate(makeTsFromDate($task->getNextRun()));
if($task->getLastRun()) if($task->getLastRun())
echo "<br/><i class=\"fa fa-stop-circle\" title=\"".getMLText('task_last_run')."\"></i> ".getLongReadableDate(makeTsFromDate($task->getLastRun())); echo "<br/><i class=\"fa fa-stop-circle\" title=\"".getMLText('task_last_run')."\"></i> ".getLongReadableDate(makeTsFromDate($task->getLastRun()));
if($task->getFailures())
echo "<br/><i class=\"fa fa-warning\" title=\"".getMLText('task_failures')."\"></i> ".$task->getFailures()." ".getMLText('task_failures');
echo "<br/><i class=\"fa fa-refresh\" title=\"".getMLText('task_frequency')."\"></i> ".$task->getFrequency(); echo "<br/><i class=\"fa fa-refresh\" title=\"".getMLText('task_frequency')."\"></i> ".$task->getFrequency();
echo "</td>"; echo "</td>";
echo "<td nowrap>"; echo "<td nowrap>";