Skip to content

Commit

Permalink
threaded adherence cache production error (#4332)
Browse files Browse the repository at this point in the history
add guard and premature exit should adherence cache be working on
timeline data purged in another thread.
  • Loading branch information
pbugni authored Aug 1, 2023
1 parent 39230b9 commit 803199f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions portal/models/qb_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
API to lookup user's status with respect to assigned questionnaire banks.
"""
from flask import current_app
from ..trace import trace
from .overall_status import OverallStatus
from .qb_timeline import QBT, ordered_qbs, update_users_QBT
Expand Down Expand Up @@ -154,7 +155,6 @@ def _status_from_current(self, cur_qbd):
# Withdrawn sanity check
if self.withdrawn_by(self.as_of_date) and (
self.overall_status != OverallStatus.withdrawn):
from flask import current_app
current_app.logger.error(
"Unexpected state %s, user %d should be withdrawn",
self.overall_status, self.user.id)
Expand Down Expand Up @@ -187,6 +187,13 @@ def older_qbds(self, last_known):
QBT.qb_iteration == cur_qbd.iteration).order_by(
QBT.at.desc(), QBT.id.desc()).with_entities(
QBT.status).first()
# production errors seen, where qb_timeline loses data. likely
# a race condition where adherence cache is using timeline rows
# when another thread purges the user's timeline. log and exit
if status is None:
current_app.logger.info(
f"timeline data disappeared mid loop {self.user.id}: {QBT}")
return
yield self.__ordered_qbs[index], str(status[0])

def _indef_init(self):
Expand Down Expand Up @@ -475,7 +482,6 @@ def warn_on_duplicate_request(self, requested_set):
Once bug is found and resolved, remove!
"""
from flask import current_app
from .questionnaire_response import QuestionnaireResponse

requested = requested_set.intersection(('irondemog', 'irondemog_v3'))
Expand Down

0 comments on commit 803199f

Please sign in to comment.