summaryrefslogtreecommitdiff
path: root/lorrycontroller/givemejob.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/givemejob.py')
-rw-r--r--lorrycontroller/givemejob.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py
index 0510a26..e40de5f 100644
--- a/lorrycontroller/givemejob.py
+++ b/lorrycontroller/givemejob.py
@@ -41,7 +41,7 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute):
logging.info('%s %s called', self.http_method, self.path)
readdb = self.open_statedb()
- if readdb.get_running_queue():
+ if readdb.get_running_queue() and not self.max_jobs_reached(readdb):
statedb = self.open_statedb()
with statedb:
lorry_infos = statedb.get_all_lorries_info()
@@ -63,6 +63,13 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute):
logging.info('No job to give MINION')
return { 'job_id': None }
+ def max_jobs_reached(self, statedb):
+ max_jobs = statedb.get_max_jobs()
+ if max_jobs is None:
+ return False
+ running_jobs = statedb.get_running_jobs()
+ return len(running_jobs) >= max_jobs
+
def ready_to_run(self, lorry_info, now):
due = lorry_info['last_run'] + lorry_info['interval']
return (lorry_info['running_job'] is None and due <= now)