From 03c194bff3befc691b5c908c2ff1d0a39d07ea74 Mon Sep 17 00:00:00 2001 From: Antoine Goutenoir Date: Fri, 25 Oct 2019 05:39:49 +0200 Subject: [PATCH] Actually implement the queue of estimations. --- flaskr/controllers/main_controller.py | 14 +++++++++++++- flaskr/models.py | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index abc60b8..54b3012 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -70,6 +70,13 @@ def compute(): # process the queue of estimation requests response = "" + count_working = Estimation.query \ + .filter_by(status=StatusEnum.working) \ + .count() + + if 0 < count_working: + return _respond("Already working on estimation.") + try: estimation = Estimation.query \ .filter_by(status=StatusEnum.pending) \ @@ -83,7 +90,12 @@ def compute(): # process the queue of estimation requests if not estimation: return _respond("No estimation in the queue.") - response += u"Processing estimation `%s` of `%s`...\n" % (estimation.id, estimation.email) + estimation.status = StatusEnum.working + db.session.commit() + + response += u"Processing estimation `%s`...\n" % ( + estimation.public_id + ) geocoder = CachedGeocoder() diff --git a/flaskr/models.py b/flaskr/models.py index 852d76c..ebb0420 100755 --- a/flaskr/models.py +++ b/flaskr/models.py @@ -17,6 +17,7 @@ db = SQLAlchemy() class StatusEnum(enum.Enum): pending = 'pending' + working = 'working' success = 'success' failure = 'failure' -- libgit2 0.21.2