diff --git a/assets/js/job/add.js b/assets/js/job/add.js index d19a803..6336ce1 100644 --- a/assets/js/job/add.js +++ b/assets/js/job/add.js @@ -128,8 +128,8 @@ function initContainerType() } function initRangeInput() { - document.querySelector('.range-input-errorlevel').addEventListener('input', event => { - document.querySelector('.range-value-errorlevel').innerHTML = event.target.value + '%'; + document.querySelector('.range-input-fail-pct').addEventListener('input', event => { + document.querySelector('.range-value-fail-pct').innerHTML = event.target.value + '%'; }) } diff --git a/src/Repository/Job.php b/src/Repository/Job.php index a25eb78..84588de 100644 --- a/src/Repository/Job.php +++ b/src/Repository/Job.php @@ -28,9 +28,9 @@ class Job extends Repository $job['service'] = $job['data']['service'] ?? ''; $job['norun'] = isset($job['lastrun']) && $job['nextrun'] > $job['lastrun']; $job['running'] = $job['running'] != 0; - $failed = count($runRepo->getRunsForJob($job['id'], true)); - $all = count($runRepo->getRunsForJob($job['id'])); - $job['needschecking'] = $all > 0 && (($failed / $all) * 100) > $job['data']['errorlevel']; + $failed = count($runRepo->getRunsForJob($job['id'], true, $job['data']['fail-days'])); + $all = count($runRepo->getRunsForJob($job['id'], false, $job['data']['fail-days'])); + $job['needschecking'] = $all > 0 && (($failed / $all) * 100) > $job['data']['fail-pct']; if(!empty($job['data']['containertype']) && $job['data']['containertype'] != 'none') { $job['host-displayname'] = $job['data']['service'] . ' on ' . $job['data']['host']; } @@ -406,7 +406,8 @@ class Job extends Repository $values['data']['crontype'] = $values['crontype']; $values['data']['hosttype'] = $values['hosttype']; $values['data']['containertype'] = $values['containertype']; - $values['data']['errorlevel'] = $values['errorlevel']; + $values['data']['fail-pct'] = $values['fail-pct'] ?? 50; + $values['data']['fail-days'] = $values['fail-days'] ?? 7; if(empty($values['data']['crontype'])) { throw new \InvalidArgumentException("Crontype cannot be empty"); diff --git a/src/Repository/Run.php b/src/Repository/Run.php index b085c96..6fd2aec 100644 --- a/src/Repository/Run.php +++ b/src/Repository/Run.php @@ -13,13 +13,17 @@ class Run extends Repository const SUCCESS = 'S'; const MANUAL = 'M'; - public function getRunsForJob(int $id, bool $onlyfailed = false, bool $ordered = true): array + public function getRunsForJob(int $id, bool $onlyfailed = false, int $maxage = NULL, bool $ordered = true): array { $runsSql = "SELECT * FROM run WHERE job_id = :job"; $params = [':job' => $id]; if ($onlyfailed) { $runsSql .= ' AND flags LIKE "%' . Run::FAILED . '%"'; } + if($maxage !== NULL) { + $runsSql .= ' AND timestamp > :timestamp'; + $params[':timestamp'] = time() - ($maxage * 24 * 60 * 60); + } if ($ordered) $runsSql .= ' ORDER by timestamp DESC'; $runsStmt = $this->dbcon->prepare($runsSql); $runsRslt = $runsStmt->executeQuery($params); diff --git a/templates/job/add.html.twig b/templates/job/add.html.twig index 7ef6314..d656faf 100644 --- a/templates/job/add.html.twig +++ b/templates/job/add.html.twig @@ -60,6 +60,11 @@ +
+ + +
+

Job details

- +
-
{% if attribute(data, 'errorlevel') is not empty %}{{ attribute(data, 'errorlevel') }}{% else %}50{% endif %}%
+
{% if attribute(data, 'fail-pct') is not empty %}{{ attribute(data, 'fail-pct') }}{% else %}50{% endif %}%
- +
+
+ + +
+

Job details