From 7b6ffeda294cccf886725591de17f4ce19564ad2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 22 Apr 2014 15:54:37 +0000 Subject: Fix minor race condition in giving out jobs Do the check for whether we're allowed to give out jobs in the transaction. --- lorrycontroller/givemejob.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py index 44bf9f7..755def0 100644 --- a/lorrycontroller/givemejob.py +++ b/lorrycontroller/givemejob.py @@ -33,10 +33,9 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): def run(self, **kwargs): logging.info('%s %s called', self.http_method, self.path) - readdb = self.open_statedb() - if readdb.get_running_queue() and not self.max_jobs_reached(readdb): - statedb = self.open_statedb() - with statedb: + statedb = self.open_statedb() + with statedb: + if statedb.get_running_queue() and not self.max_jobs_reached(statedb): lorry_infos = statedb.get_all_lorries_info() now = statedb.get_current_time() for lorry_info in lorry_infos: -- cgit v1.2.1