From c491acc03665213e01e40fc9ef81f5e326cf9ff9 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 8 Sep 2014 17:11:24 +0000 Subject: Add lists of failed, all jobs to lorry spec info This adds them to both the JSON and HTML outputs. --- lorrycontroller/showlorry.py | 35 +++++++++++++++++++++++------------ lorrycontroller/statedb.py | 13 +++++++++++++ templates/lorry.tpl | 25 +++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/lorrycontroller/showlorry.py b/lorrycontroller/showlorry.py index fc336a5..19f9429 100644 --- a/lorrycontroller/showlorry.py +++ b/lorrycontroller/showlorry.py @@ -24,32 +24,43 @@ import bottle import lorrycontroller -class ShowLorry(lorrycontroller.LorryControllerRoute): +class ShowLorryBase(object): + + def get_lorry_info_with_job_lists(self, statedb, path): + obj= statedb.get_lorry_info(path) + obj['jobs'] = statedb.get_jobs_for_lorry(path) + obj['failed_jobs'] = statedb.get_failed_jobs_for_lorry(path) + return obj + + +class ShowLorry(ShowLorryBase, lorrycontroller.LorryControllerRoute): http_method = 'GET' path = '/1.0/lorry/' def run(self, **kwargs): logging.info('%s %s called', self.http_method, self.path) - statedb = self.open_statedb() - try: - return statedb.get_lorry_info(kwargs['path']) - except lorrycontroller.LorryNotFoundError as e: - bottle.abort(404, str(e)) + with self.open_statedb() as statedb: + try: + return self.get_lorry_info_with_job_lists(statedb, kwargs['path']) + except lorrycontroller.LorryNotFoundError as e: + bottle.abort(404, str(e)) -class ShowLorryHTML(lorrycontroller.LorryControllerRoute): +class ShowLorryHTML(ShowLorryBase, lorrycontroller.LorryControllerRoute): http_method = 'GET' path = '/1.0/lorry-html/' def run(self, **kwargs): logging.info('%s %s called', self.http_method, self.path) - statedb = self.open_statedb() - try: - lorry_info = statedb.get_lorry_info(kwargs['path']) - except lorrycontroller.LorryNotFoundError as e: - bottle.abort(404, str(e)) + + with self.open_statedb() as statedb: + try: + lorry_info = self.get_lorry_info_with_job_lists( + statedb, kwargs['path']) + except lorrycontroller.LorryNotFoundError as e: + bottle.abort(404, str(e)) renderer = lorrycontroller.StatusRenderer() shower = lorrycontroller.JobShower() diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py index fd7857d..7a26098 100644 --- a/lorrycontroller/statedb.py +++ b/lorrycontroller/statedb.py @@ -473,6 +473,19 @@ class StateDB(object): 'output': row[10], } + def get_jobs_for_lorry(self, path): + c = self.get_cursor() + c.execute('SELECT job_id FROM jobs WHERE path=?', (path,)) + return [row[0] for row in c.fetchall()] + + def get_failed_jobs_for_lorry(self, path): + c = self.get_cursor() + c.execute( + 'SELECT job_id FROM jobs ' + 'WHERE path=? AND exit != \'no\' AND exit != 0', + (path,)) + return [row[0] for row in c.fetchall()] + def add_new_job(self, job_id, host, pid, path, started): logging.debug( 'StateDB.add_new_job(%r, %r, %r, %r, %r) called', diff --git a/templates/lorry.tpl b/templates/lorry.tpl index fad85cd..7c475e0 100644 --- a/templates/lorry.tpl +++ b/templates/lorry.tpl @@ -40,5 +40,30 @@

Updated: {{timestamp}}

+

Failed jobs for this Lorry

+ +% if lorry['failed_jobs']: +

+% for job_id in lorry['failed_jobs']: +{{job_id}} +% end +

+% else: +

No failed jobs.

+% end + +

All jobs for this lorry

+ +% if lorry['jobs']: +

+% for job_id in lorry['jobs']: +{{job_id}} +% end +

+% else: +

No jobs.

+% end + + -- cgit v1.2.1