Commit 03c194bff3befc691b5c908c2ff1d0a39d07ea74
1 parent
d61e225e
Exists in
master
Actually implement the queue of estimations.
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
flaskr/controllers/main_controller.py
@@ -70,6 +70,13 @@ def compute(): # process the queue of estimation requests | @@ -70,6 +70,13 @@ def compute(): # process the queue of estimation requests | ||
70 | 70 | ||
71 | response = "" | 71 | response = "" |
72 | 72 | ||
73 | + count_working = Estimation.query \ | ||
74 | + .filter_by(status=StatusEnum.working) \ | ||
75 | + .count() | ||
76 | + | ||
77 | + if 0 < count_working: | ||
78 | + return _respond("Already working on estimation.") | ||
79 | + | ||
73 | try: | 80 | try: |
74 | estimation = Estimation.query \ | 81 | estimation = Estimation.query \ |
75 | .filter_by(status=StatusEnum.pending) \ | 82 | .filter_by(status=StatusEnum.pending) \ |
@@ -83,7 +90,12 @@ def compute(): # process the queue of estimation requests | @@ -83,7 +90,12 @@ def compute(): # process the queue of estimation requests | ||
83 | if not estimation: | 90 | if not estimation: |
84 | return _respond("No estimation in the queue.") | 91 | return _respond("No estimation in the queue.") |
85 | 92 | ||
86 | - response += u"Processing estimation `%s` of `%s`...\n" % (estimation.id, estimation.email) | 93 | + estimation.status = StatusEnum.working |
94 | + db.session.commit() | ||
95 | + | ||
96 | + response += u"Processing estimation `%s`...\n" % ( | ||
97 | + estimation.public_id | ||
98 | + ) | ||
87 | 99 | ||
88 | geocoder = CachedGeocoder() | 100 | geocoder = CachedGeocoder() |
89 | 101 |
flaskr/models.py
@@ -17,6 +17,7 @@ db = SQLAlchemy() | @@ -17,6 +17,7 @@ db = SQLAlchemy() | ||
17 | 17 | ||
18 | class StatusEnum(enum.Enum): | 18 | class StatusEnum(enum.Enum): |
19 | pending = 'pending' | 19 | pending = 'pending' |
20 | + working = 'working' | ||
20 | success = 'success' | 21 | success = 'success' |
21 | failure = 'failure' | 22 | failure = 'failure' |
22 | 23 |