summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-24 16:39:33 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-02-24 16:39:33 +0000
commit8e9849907e8bb64c3964373c82d39727d9ab8550 (patch)
treeffc8a02ab4548079ce59ae9193228aab573f30b4
parent31ab6e6263d3de832cba1124c2a74c28da47c8ce (diff)
downloadlorry-controller-8e9849907e8bb64c3964373c82d39727d9ab8550.tar.gz
Implement /1.0/list-running-jobs
-rwxr-xr-xlorry-controller-webapp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp
index 0ff9d65..e70b132 100755
--- a/lorry-controller-webapp
+++ b/lorry-controller-webapp
@@ -288,6 +288,13 @@ class StateDB(object):
raise WrongNumberLorriesRunningJob(job_id, len(rows))
return rows[0][0]
+ def get_running_jobs(self):
+ logging.debug('StateDB.get_running_jobs() called')
+ c = self.get_cursor()
+ c.execute(
+ 'SELECT running_job FROM lorries WHERE running_job IS NOT NULL')
+ return [row[0] for row in c.fetchall()]
+
class LorryControllerRoute(object):
@@ -597,6 +604,20 @@ class JobUpdate(LorryControllerRoute):
self.statedb.set_running_job(path, None)
+class ListRunningJobs(LorryControllerRoute):
+
+ http_method = 'GET'
+ path = '/1.0/list-running-jobs'
+
+ def run(self, **kwargs):
+ logging.debug('%s %s called', self.http_method, self.path)
+
+ job_ids = self.statedb.get_running_jobs()
+ return {
+ 'running_jobs': job_ids,
+ }
+
+
class WEBAPP(cliapp.Application):
def add_settings(self):