diff options
-rw-r--r-- | lorrycontroller/__init__.py | 4 | ||||
-rw-r--r-- | lorrycontroller/status.py | 27 | ||||
-rw-r--r-- | templates/failures.tpl | 45 | ||||
-rw-r--r-- | templates/status.tpl | 2 |
4 files changed, 72 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) 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 @@ +<!DOCTYPE HTML> +<html> + <head> + <title>Failing lorries</title> + <link rel="stylesheet" href="/lc-static/style.css" type="text/css" /> + </head> + <body> + <h1>Failing lorries</h1> + + <p>See the <a href="/1.0/status-html">full status</a>.</p> + + <table> + <tr> + <th>Path</th> + <th>Due</th> + <th>Last run exit</th> + <th>Job?</th> + </tr> +% 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'])): + <tr> + <td><a href="/1.0/lorry-html/{{spec['path']}}">{{spec['path']}}</a></td> + <td nowrap>{{spec['due_nice']}}</td> + <td> + <details> + <summary>{{spec['last_run_exit']}}: Show log</summary> + <p><pre>{{spec['last_run_error']}}</pre></p> + </details> + </td> +% if spec['running_job']: + <td><a href="/1.0/job-html/{{spec['running_job']}}">{{spec['running_job']}}</a></td> +% else: + <td></td> +% end + </tr> +% end + </table> + + <hr> + + <p>Updated: {{timestamp}}</p> + + </body> +</html> 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: <p>See separate list of <a href="/1.0/list-jobs-html">all jobs that have ever been started</a>.</p> + +<p>See the list of <a href="/1.0/failures-html">failing lorries</a>.</p> % end <h2>Run-queue</h2> |