diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-04-22 15:54:37 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-04-22 15:54:37 +0000 |
commit | 7b6ffeda294cccf886725591de17f4ce19564ad2 (patch) | |
tree | b8bb953de0268d323f6132305ff98fe709f2b626 /lorrycontroller | |
parent | 3002140e01725a7cbf3195741206526177101263 (diff) | |
download | lorry-controller-7b6ffeda294cccf886725591de17f4ce19564ad2.tar.gz |
Fix minor race condition in giving out jobs
Do the check for whether we're allowed to give out jobs in the
transaction.
Diffstat (limited to 'lorrycontroller')
-rw-r--r-- | lorrycontroller/givemejob.py | 7 |
1 files 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: |