summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-24 12:51:56 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-24 12:51:56 +0000
commit3694afb15717de54814fbf9fa3203bcddac37bd0 (patch)
tree21f852fd2ebd4fd72ddce362060cec440b59992f
parenta00fe4ed498b617c4cc4c0874a5ab58600ae3ae5 (diff)
downloadlorry-controller-3694afb15717de54814fbf9fa3203bcddac37bd0.tar.gz
Mark scheduled jobs as such
-rwxr-xr-xlorry-controller-webapp37
-rw-r--r--yarns.webapp/040-running-jobs.yarn5
2 files changed, 31 insertions, 11 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp
index c01bf37..efd7cfa 100755
--- a/lorry-controller-webapp
+++ b/lorry-controller-webapp
@@ -85,6 +85,7 @@ class StateDB(object):
'path TEXT PRIMARY KEY, '
'text TEXT, '
'generated INT, '
+ 'running_job INT, '
'due INT, '
'interval INT '
')')
@@ -110,11 +111,11 @@ class StateDB(object):
self._conn.commit()
def get_lorry_info(self, path):
- logging.debug('StateDB.get_lorry_info called, path=%r', path)
+ logging.debug('StateDB.get_lorry_info(path=%r) called', path)
self._open()
c = self._conn.cursor()
c.execute(
- 'SELECT path, text, generated, due, interval '
+ 'SELECT path, text, generated, due, interval, running_job '
'FROM lorries WHERE path IS ?',
(path,))
row = c.fetchone()
@@ -126,6 +127,7 @@ class StateDB(object):
'generated': row[2],
'due': row[3],
'interval': row[4],
+ 'running_job': row[5],
}
def get_all_lorries_info(self):
@@ -133,7 +135,8 @@ class StateDB(object):
self._open()
c = self._conn.cursor()
c.execute(
- 'SELECT path, text, generated, due, interval FROM lorries '
+ 'SELECT path, text, generated, due, interval, running_job '
+ 'FROM lorries '
'ORDER BY due')
return [
{
@@ -142,6 +145,7 @@ class StateDB(object):
'generated': row[2],
'due': row[3],
'interval': row[4],
+ 'running_job': row[5],
}
for row in c.fetchall()
]
@@ -176,9 +180,9 @@ class StateDB(object):
c.execute('BEGIN TRANSACTION')
c.execute(
'INSERT OR REPLACE INTO lorries '
- '(path, text, generated, due, interval) '
- 'VALUES (?, ?, ?, ?, ?)',
- (path, text, generated, due, interval))
+ '(path, text, generated, due, interval, running_job) '
+ 'VALUES (?, ?, ?, ?, ?, ?)',
+ (path, text, generated, due, interval, None))
self._conn.commit()
def remove_lorry(self, path):
@@ -189,6 +193,15 @@ class StateDB(object):
c.execute('DELETE FROM lorries WHERE path IS ?', (path,))
self._conn.commit()
+ def set_running_job(self, path, job_id):
+ logging.debug(
+ 'StateDB.set_running_job(%r, %r) called', path, job_id)
+ self._open()
+ c = self._conn.cursor()
+ c.execute(
+ 'UPDATE lorries SET running_job=? WHERE path=?',
+ (job_id, path))
+
class LorryControllerRoute(object):
@@ -429,11 +442,13 @@ class GiveMeJob(LorryControllerRoute):
def run(self, **kwargs):
logging.debug('%s %s called', self.http_method, self.path)
- paths = self.statedb.get_lorries_paths()
- if paths:
- return { 'job-id': paths[0] }
- else:
- return { 'job-id': None }
+ lorry_infos = self.statedb.get_all_lorries_info()
+ for lorry_info in lorry_infos:
+ if lorry_info['running_job'] is None:
+ path = lorry_info['path']
+ self.statedb.set_running_job(path, 1)
+ return { 'job-id': path}
+ return { 'job-id': None }
class WEBAPP(cliapp.Application):
diff --git a/yarns.webapp/040-running-jobs.yarn b/yarns.webapp/040-running-jobs.yarn
index ea5b72e..8d35ab0 100644
--- a/yarns.webapp/040-running-jobs.yarn
+++ b/yarns.webapp/040-running-jobs.yarn
@@ -27,3 +27,8 @@ that job now.
WHEN admin makes request GET /1.0/read-configuration
AND admin makes request GET /1.0/give-me-job
THEN response has job-id set to "upstream/foo"
+
+Requesting another job should now again return null.
+
+ WHEN admin makes request GET /1.0/give-me-job
+ THEN response has job-id set to null