26
26
from ..timeout_lock import TimeoutLock , LockTimeout
27
27
28
28
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)
29
30
OPT_OUT_DELAY = 1800 # seconds to allow user to provide opt-out choices
30
31
31
32
class EMPRO_state (StateMachine ):
@@ -296,6 +297,9 @@ def process_processed(ts):
296
297
# necessary to make deep copy in order to update DB JSON
297
298
triggers = copy .deepcopy (ts .triggers )
298
299
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' ]} " )
299
303
triggers ['actions' ] = dict ()
300
304
triggers ['actions' ]['email' ] = list ()
301
305
@@ -413,6 +417,7 @@ def process_pending_actions(ts):
413
417
try :
414
418
with TimeoutLock (
415
419
key = EMPRO_LOCK_KEY .format (user_id = ts .user_id ),
420
+ expires = EMPRO_LOCK_EXPIRATION ,
416
421
timeout = NEVER_WAIT ):
417
422
process_processed (ts )
418
423
db .session .commit ()
@@ -425,6 +430,7 @@ def process_pending_actions(ts):
425
430
try :
426
431
with TimeoutLock (
427
432
key = EMPRO_LOCK_KEY .format (user_id = ts .user_id ),
433
+ expires = EMPRO_LOCK_EXPIRATION ,
428
434
timeout = NEVER_WAIT ):
429
435
process_pending_actions (ts )
430
436
db .session .commit ()
@@ -555,7 +561,9 @@ def extract_observations(questionnaire_response_id, override_state=False):
555
561
556
562
# given asynchronous possibility, require user's EMPRO lock
557
563
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 ):
559
567
ts = users_trigger_state (qnr .subject_id )
560
568
sm = EMPRO_state (ts )
561
569
if not override_state :
0 commit comments