summaryrefslogtreecommitdiff
path: root/lorrycontroller/statedb.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/statedb.py')
-rw-r--r--lorrycontroller/statedb.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py
index 8316c9a..2d223e0 100644
--- a/lorrycontroller/statedb.py
+++ b/lorrycontroller/statedb.py
@@ -61,14 +61,12 @@ class StateDB(object):
('from_trovehost', 'TEXT'),
('from_path', 'TEXT'),
('running_job', 'INT'),
- ('kill_job', 'INT'),
('last_run', 'INT'),
('interval', 'INT'),
('lorry_timeout', 'INT'),
('disk_usage', 'INT'),
]
self.lorries_booleans = [
- 'kill_job',
]
if self._conn is None:
@@ -131,6 +129,7 @@ class StateDB(object):
'pid INT, '
'started INT, '
'ended INT, '
+ 'kill INT, '
'path TEXT, '
'exit TEXT, '
'disk_usage INT, '
@@ -356,10 +355,10 @@ class StateDB(object):
c.execute(
'INSERT INTO lorries '
'(path, text, from_trovehost, from_path, last_run, interval, '
- 'lorry_timeout, running_job, kill_job) '
- 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
+ 'lorry_timeout, running_job) '
+ 'VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
(path, text, from_trovehost, from_path, 0,
- interval, timeout, None, 0))
+ interval, timeout, None))
else:
c = self.get_cursor()
c.execute(
@@ -407,8 +406,8 @@ class StateDB(object):
'SELECT running_job FROM lorries WHERE running_job IS NOT NULL')
return [row[0] for row in c.fetchall()]
- def set_kill_job(self, path, value):
- logging.debug('StateDB.set_kill_job(%r, %r) called', path, value)
+ def set_kill_job(self, job_id, value):
+ logging.debug('StateDB.set_kill_job(%r, %r) called', job_id, value)
assert self.in_transaction
if value:
value = 1
@@ -416,8 +415,8 @@ class StateDB(object):
value = 0
c = self.get_cursor()
c.execute(
- 'UPDATE lorries SET kill_job=? WHERE path=?',
- (value, path))
+ 'UPDATE jobs SET kill=? WHERE job_id=?',
+ (value, job_id))
def set_lorry_last_run(self, path, last_run):
logging.debug(
@@ -452,6 +451,26 @@ class StateDB(object):
c.execute('SELECT job_id FROM jobs')
return [row[0] for row in c.fetchall()]
+ def get_job_info(self, job_id):
+ c = self.get_cursor()
+ c.execute(
+ 'SELECT job_id, host, pid, started, ended, kill, path, exit, '
+ 'disk_usage, output FROM jobs WHERE job_id=?',
+ (job_id,))
+ row = c.fetchone()
+ return {
+ 'job_id': row[0],
+ 'host': row[1],
+ 'pid': row[2],
+ 'started': row[3],
+ 'ended': row[4],
+ 'kill': row[5],
+ 'path': row[6],
+ 'exit': row[7],
+ 'disk_usage': row[8],
+ 'output': row[9],
+ }
+
def add_new_job(self, job_id, host, pid, path, started):
logging.debug(
'StateDB.add_new_job(%r, %r, %r, %r, %r) called',
@@ -459,9 +478,9 @@ class StateDB(object):
assert self.in_transaction
c = self.get_cursor()
c.execute(
- 'INSERT INTO jobs (job_id, host, pid, path, started) '
- 'VALUES (?, ?, ?, ?, ?)',
- (job_id, host, pid, path, started))
+ 'INSERT INTO jobs (job_id, host, pid, path, started, kill) '
+ 'VALUES (?, ?, ?, ?, ?, ?)',
+ (job_id, host, pid, path, started, 0))
def get_job_minion_host(self, job_id):
c = self.get_cursor()