summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez Piedehierro <palvarez89@gmail.com>2017-07-07 01:04:18 +0100
committerPedro Alvarez Piedehierro <palvarez89@gmail.com>2017-07-08 03:22:40 +0100
commit1e10d0d1fe400063ea1b3adbe90b83fb9f7fcf69 (patch)
tree8341a471838941327323483ac6a2a1da6d7c86dd
parentcfbd91e737198757c6b2fd876a248da7256bf86e (diff)
downloadlorry-controller-1e10d0d1fe400063ea1b3adbe90b83fb9f7fcf69.tar.gz
jobupdate: Store job information in lorry if publishing failures
-rw-r--r--lorrycontroller/jobupdate.py6
-rw-r--r--lorrycontroller/statedb.py10
2 files changed, 16 insertions, 0 deletions
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)