From 86cba38e711a84641ac14fc75dfbe67ddcb3a6d3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 24 Feb 2014 18:01:53 +0000 Subject: Only schedule jobs when running_queue is set to true --- lorry-controller-webapp | 24 +++++++++++++----------- yarns.webapp/040-running-jobs.yarn | 11 +++++++++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lorry-controller-webapp b/lorry-controller-webapp index 468f941..8543899 100755 --- a/lorry-controller-webapp +++ b/lorry-controller-webapp @@ -610,17 +610,19 @@ class GiveMeJob(LorryControllerRoute): def run(self, **kwargs): logging.debug('%s %s called', self.http_method, self.path) - with self.statedb.transaction(): - 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'] - running_job = self.statedb.get_next_job_id() - self.statedb.set_running_job(path, running_job) - return { - 'job_id': running_job, - 'path': path, - } + + if self.statedb.get_running_queue(): + with self.statedb.transaction(): + 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'] + running_job = self.statedb.get_next_job_id() + self.statedb.set_running_job(path, running_job) + return { + 'job_id': running_job, + 'path': path, + } return { 'job_id': None } diff --git a/yarns.webapp/040-running-jobs.yarn b/yarns.webapp/040-running-jobs.yarn index 2c4a076..7d5a319 100644 --- a/yarns.webapp/040-running-jobs.yarn +++ b/yarns.webapp/040-running-jobs.yarn @@ -22,13 +22,19 @@ To start with, with an empty run-queue, nothing should be scheduled. WHEN admin makes request GET /1.0/list-running-jobs THEN response has running_jobs set to [] -Add a Lorry spec to the run-queue, and request a job. We should get -that job now. +Add a Lorry spec to the run-queue, and request a job. We still +shouldn't get a job, since the queue isn't set to run yet. GIVEN Lorry file CONFGIT/foo.lorry with {"foo":{"type":"git","url":"git://foo"}} 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 null + +Enable the queue, and off we go. + + WHEN admin makes request GET /1.0/start-queue + AND admin makes request GET /1.0/give-me-job THEN response has job_id set to 1 AND response has path set to "upstream/foo" @@ -67,6 +73,7 @@ we did for the successful job scenario. AND a running WEBAPP AND Lorry file CONFGIT/foo.lorry with {"foo":{"type":"git","url":"git://foo"}} WHEN admin makes request GET /1.0/read-configuration + AND admin makes request GET /1.0/start-queue AND admin makes request GET /1.0/give-me-job THEN response has job_id set to 1 AND response has path set to "upstream/foo" -- cgit v1.2.1