summaryrefslogtreecommitdiff
path: root/lorrycontroller
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-09-29 21:41:54 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-10-06 01:50:09 +0100
commit19e8f1bdf0205cc26ef7679a20c3f38b7a7cb9a7 (patch)
tree21646ef8dc6a8f82b37e07a447a8dd8243559669 /lorrycontroller
parent2beec955ccf893fada8381aa821189aeddd6ca9b (diff)
downloadlorry-controller-19e8f1bdf0205cc26ef7679a20c3f38b7a7cb9a7.tar.gz
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.
Diffstat (limited to 'lorrycontroller')
-rw-r--r--lorrycontroller/__init__.py4
-rw-r--r--lorrycontroller/status.py27
2 files changed, 25 insertions, 6 deletions
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)