summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-24 17:49:24 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-24 17:49:24 +0000
commitc5eae90d75e7752c9d812f6b92d04c9179ebc590 (patch)
tree060209f9217c2faf32070b79ae0bf4e1c093f38e
parentdcc1efcd847850fc3b7ed53e89ab4d4806465527 (diff)
downloadlorry-controller-c5eae90d75e7752c9d812f6b92d04c9179ebc590.tar.gz
Assign job ids properly
While 1 is a perfectly nice number, having every job get the same id is not entirely what is supposed to happen.
-rwxr-xr-xlorry-controller-webapp20
1 files changed, 19 insertions, 1 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp
index aa62877..3b73527 100755
--- a/lorry-controller-webapp
+++ b/lorry-controller-webapp
@@ -156,9 +156,12 @@ class StateDB(object):
c = self._conn.cursor()
c.execute('BEGIN TRANSACTION')
+ # Table for holding the "are we scheduling jobs" value.
c.execute('CREATE TABLE IF NOT EXISTS running_queue (running INT)')
c.execute('INSERT INTO running_queue VALUES (0)')
+ # Table for all the known lorries (the "run queue").
+
self.lorries_fields = [
('path', 'TEXT PRIMARY KEY'),
('text', 'TEXT'),
@@ -179,6 +182,11 @@ class StateDB(object):
c.execute(
'CREATE TABLE IF NOT EXISTS lorries (%s)' % fields_sql)
+ # Table for the next available job id.
+ c.execute('CREATE TABLE IF NOT EXISTS next_job_id (job_id INT)')
+ c.execute('INSERT INTO next_job_id VALUES (1)')
+
+ # Done.
self._conn.commit()
@property
@@ -317,6 +325,16 @@ class StateDB(object):
'UPDATE lorries SET kill_job=? WHERE path=?',
(value, path))
+ def get_next_job_id(self):
+ logging.debug('StateDB.get_next_job_id called')
+ assert self.in_transaction
+ c = self.get_cursor()
+ c.execute('SELECT job_id FROM next_job_id')
+ row = c.fetchone()
+ job_id = row[0]
+ c.execute('UPDATE next_job_id SET job_id=?', (job_id + 1,))
+ return job_id
+
class LorryControllerRoute(object):
@@ -597,7 +615,7 @@ class GiveMeJob(LorryControllerRoute):
for lorry_info in lorry_infos:
if lorry_info['running_job'] is None:
path = lorry_info['path']
- running_job = 1
+ running_job = self.statedb.get_next_job_id()
self.statedb.set_running_job(path, running_job)
return {
'job_id': running_job,