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-10 21:25:54 +0100
commit094dfb57b43c37e6653120364b247b17071549ac (patch)
treea951de744c83404b23e2e0581b4db3e487d4c712
parent247cc6eaba7611cf7527c4ae72e5a6ff1654fb2c (diff)
downloadlorry-controller-094dfb57b43c37e6653120364b247b17071549ac.tar.gz
jobupdate: Store job information in lorry if publishing failures
-rw-r--r--lorrycontroller/jobupdate.py7
-rw-r--r--lorrycontroller/statedb.py10
2 files changed, 16 insertions, 1 deletions
diff --git a/lorrycontroller/jobupdate.py b/lorrycontroller/jobupdate.py
index efc9ce1..ec7e533 100644
--- a/lorrycontroller/jobupdate.py
+++ b/lorrycontroller/jobupdate.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2014 Codethink Limited
+# Copyright (C) 2014-2017 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -51,6 +51,11 @@ class JobUpdate(lorrycontroller.LorryControllerRoute):
lorry_info = statedb.get_lorry_info(path)
if exit is not None and exit != 'no':
+ if 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 8c62a31..99ea7fc 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)