From 19e8f1bdf0205cc26ef7679a20c3f38b7a7cb9a7 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Tue, 29 Sep 2020 21:41:54 +0100 Subject: Add a page listing failing lorries Provide a status page that lists only the lorries that failed to update on the last attempt. This will make it easier to spot problems that require an update to the lorry configuration. Reuse some of the existing status page logic and render the run queue with a different template. Add a link to this page from the status page. Closes #20. --- lorrycontroller/__init__.py | 4 ++-- lorrycontroller/status.py | 27 +++++++++++++++++++++++---- templates/failures.tpl | 45 +++++++++++++++++++++++++++++++++++++++++++++ templates/status.tpl | 2 ++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 templates/failures.tpl diff --git a/lorrycontroller/__init__.py b/lorrycontroller/__init__.py index b2510dc..ef9c977 100644 --- a/lorrycontroller/__init__.py +++ b/lorrycontroller/__init__.py @@ -21,7 +21,7 @@ from .statedb import ( HostNotFoundError) from .route import LorryControllerRoute from .readconf import ReadConfiguration -from .status import Status, StatusHTML, StatusRenderer +from .status import Status, StatusHTML, StatusRenderer, FailuresHTML from .listqueue import ListQueue from .showlorry import ShowLorry, ShowLorryHTML from .startstopqueue import StartQueue, StopQueue @@ -70,7 +70,7 @@ __all__ = [ 'LorryNotFoundError', 'WrongNumberLorriesRunningJob', 'HostNotFoundError', 'LorryControllerRoute', 'ReadConfiguration', - 'Status', 'StatusHTML', 'StatusRenderer', + 'Status', 'StatusHTML', 'StatusRenderer', 'FailuresHTML', 'ListQueue', 'ShowLorry', 'ShowLorryHTML', 'StartQueue', 'StopQueue', diff --git a/lorrycontroller/status.py b/lorrycontroller/status.py index 8483485..df39470 100644 --- a/lorrycontroller/status.py +++ b/lorrycontroller/status.py @@ -29,19 +29,24 @@ class StatusRenderer(object): '''Helper class for rendering service status as JSON/HTML''' - def get_status_as_dict(self, statedb, work_directory): + def get_queue_status_as_dict(self, statedb): now = statedb.get_current_time() - status = { - 'running_queue': statedb.get_running_queue(), + return { 'timestamp': time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime(now)), 'run_queue': self.get_run_queue(statedb), + } + + def get_status_as_dict(self, statedb, work_directory): + status = self.get_queue_status_as_dict(statedb) + status.update({ + 'running_queue': statedb.get_running_queue(), 'hosts': self.get_hosts(statedb), 'warning_msg': '', 'max_jobs': self.get_max_jobs(statedb), 'links': True, 'publish_failures': True, - } + }) status.update(self.get_free_disk_space(work_directory)) return status @@ -209,3 +214,17 @@ class StatusHTML(lorrycontroller.LorryControllerRoute): self.app_settings['publish-failures']) return renderer.render_status_as_html( self._templates['status'], status) + + +class FailuresHTML(lorrycontroller.LorryControllerRoute): + + http_method = 'GET' + path = '/1.0/failures-html' + + def run(self, **kwargs): + logging.info('%s %s called', self.http_method, self.path) + renderer = StatusRenderer() + with self.open_statedb() as statedb: + status = renderer.get_queue_status_as_dict(statedb) + return renderer.render_status_as_html( + self._templates['failures'], status) diff --git a/templates/failures.tpl b/templates/failures.tpl new file mode 100644 index 0000000..5c7b6ce --- /dev/null +++ b/templates/failures.tpl @@ -0,0 +1,45 @@ + + + + Failing lorries + + + +

Failing lorries

+ +

See the full status.

+ + + + + + + + +% failures = [spec for spec in run_queue +% if spec['last_run_exit'] not in [None, '0']] +% for spec in sorted(failures, key=(lambda spec: spec['path'])): + + + + +% if spec['running_job']: + +% else: + +% end + +% end +
PathDueLast run exitJob?
{{spec['path']}}{{spec['due_nice']}} +
+ {{spec['last_run_exit']}}: Show log +

{{spec['last_run_error']}}

+
+
{{spec['running_job']}}
+ +
+ +

Updated: {{timestamp}}

+ + + diff --git a/templates/status.tpl b/templates/status.tpl index ff572de..61c3aa9 100644 --- a/templates/status.tpl +++ b/templates/status.tpl @@ -100,6 +100,8 @@ % if links:

See separate list of all jobs that have ever been started.

+ +

See the list of failing lorries.

% end

Run-queue

-- cgit v1.2.1