diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-11-17 10:22:33 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-11-17 10:22:33 +0000 |
commit | 689174532cc4920d2ef96bcebeb8a1adaf985804 (patch) | |
tree | 6391e7df464371b7a55aac8c1fc35b7b4b9d5d29 /lorrycontroller | |
parent | e15d8f5c2a6ea406b4cc8b60b2fd79dc36aeecd2 (diff) | |
parent | c491acc03665213e01e40fc9ef81f5e326cf9ff9 (diff) | |
download | lorry-controller-689174532cc4920d2ef96bcebeb8a1adaf985804.tar.gz |
Merge remote-tracking branch 'origin/baserock/liw/lc-list-failed-jobs'
Reviewed-By: Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
Reviewed-By: Sam Thursfield <sam.thursfield@codethink.co.uk>
Diffstat (limited to 'lorrycontroller')
-rw-r--r-- | lorrycontroller/showlorry.py | 35 | ||||
-rw-r--r-- | lorrycontroller/statedb.py | 13 |
2 files changed, 36 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/<path:path>' 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/<path:path>' 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', |