From 1e10d0d1fe400063ea1b3adbe90b83fb9f7fcf69 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Piedehierro Date: Fri, 7 Jul 2017 01:04:18 +0100 Subject: jobupdate: Store job information in lorry if publishing failures --- lorrycontroller/jobupdate.py | 6 ++++++ lorrycontroller/statedb.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lorrycontroller/jobupdate.py b/lorrycontroller/jobupdate.py index efc9ce1..51a1bf4 100644 --- a/lorrycontroller/jobupdate.py +++ b/lorrycontroller/jobupdate.py @@ -51,6 +51,12 @@ class JobUpdate(lorrycontroller.LorryControllerRoute): lorry_info = statedb.get_lorry_info(path) if exit is not None and exit != 'no': + # Get output if enabled, and if failure + if self.app_settings['publish-failures'] and exit != '0': + job_output = statedb.get_job_output(job_id) + else: + job_output = '' + statedb.set_lorry_last_run_exit_and_output(path, exit, job_output) statedb.set_lorry_last_run(path, int(now)) statedb.set_running_job(path, None) statedb.set_job_exit(job_id, exit, int(now), disk_usage) diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py index 923a0b8..a417c88 100644 --- a/lorrycontroller/statedb.py +++ b/lorrycontroller/statedb.py @@ -440,6 +440,16 @@ class StateDB(object): 'UPDATE lorries SET last_run=? WHERE path=?', (last_run, path)) + def set_lorry_last_run_exit_and_output(self, path, exit, output): + logging.debug( + 'StateDB.set_lorry_last_run_exit_and_output(%r, %r, %r) called', + path, exit, output) + assert self.in_transaction + c = self.get_cursor() + c.execute( + 'UPDATE lorries SET last_run_exit=?, last_run_error=? WHERE path=?', + (exit, output, path)) + def set_lorry_disk_usage(self, path, disk_usage): logging.debug( 'StateDB.set_lorry_disk_usage(%r, %r) called', path, disk_usage) -- cgit v1.2.1