Skip to content

Commit 25cb849

Browse files
committed
IRONN-270 fix. TimoutLock used to prevent concurrent EMPRO trigger states overwrites was expiring prior to completion.
1 parent 8cd97f0 commit 25cb849

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

portal/trigger_states/empro_states.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from ..timeout_lock import TimeoutLock, LockTimeout
2727

2828
EMPRO_LOCK_KEY = "empro-trigger-state-lock-{user_id}"
29+
EMPRO_LOCK_EXPIRATION = 2*60*60 # yes, 2 hours given interruptions by big jobs (see IRONN-270)
2930
OPT_OUT_DELAY = 1800 # seconds to allow user to provide opt-out choices
3031

3132
class EMPRO_state(StateMachine):
@@ -296,6 +297,9 @@ def process_processed(ts):
296297
# necessary to make deep copy in order to update DB JSON
297298
triggers = copy.deepcopy(ts.triggers)
298299
triggers['action_state'] = 'not applicable'
300+
if 'actions' in triggers:
301+
current_app.logger.error(
302+
f"unexpected existing 'actions' in trigger_states.triggers({ts.id}): {triggers['actions']}")
299303
triggers['actions'] = dict()
300304
triggers['actions']['email'] = list()
301305

@@ -413,6 +417,7 @@ def process_pending_actions(ts):
413417
try:
414418
with TimeoutLock(
415419
key=EMPRO_LOCK_KEY.format(user_id=ts.user_id),
420+
expires=EMPRO_LOCK_EXPIRATION,
416421
timeout=NEVER_WAIT):
417422
process_processed(ts)
418423
db.session.commit()
@@ -425,6 +430,7 @@ def process_pending_actions(ts):
425430
try:
426431
with TimeoutLock(
427432
key=EMPRO_LOCK_KEY.format(user_id=ts.user_id),
433+
expires=EMPRO_LOCK_EXPIRATION,
428434
timeout=NEVER_WAIT):
429435
process_pending_actions(ts)
430436
db.session.commit()
@@ -555,7 +561,9 @@ def extract_observations(questionnaire_response_id, override_state=False):
555561

556562
# given asynchronous possibility, require user's EMPRO lock
557563
with TimeoutLock(
558-
key=EMPRO_LOCK_KEY.format(user_id=qnr.subject_id), timeout=60):
564+
key=EMPRO_LOCK_KEY.format(user_id=qnr.subject_id),
565+
expires=EMPRO_LOCK_EXPIRATION,
566+
timeout=EMPRO_LOCK_EXPIRATION+60):
559567
ts = users_trigger_state(qnr.subject_id)
560568
sm = EMPRO_state(ts)
561569
if not override_state:

0 commit comments

Comments
 (0)