diff --git a/isacc_messaging/api/isacc_record_creator.py b/isacc_messaging/api/isacc_record_creator.py index 12912a4..e72f5ea 100644 --- a/isacc_messaging/api/isacc_record_creator.py +++ b/isacc_messaging/api/isacc_record_creator.py @@ -325,11 +325,11 @@ def score_message(self, message): def execute_requests(self) -> Tuple[List[dict], List[dict]]: """ - For all due CommunicationRequests, generate SMS, create Communication resource, and update CommunicationRequest + For all due CommunicationRequests (up to throttle limit), generate SMS, create Communication resource, and update CommunicationRequest """ successes = [] errors = [] - + throttle_limit = 30 # conservative value based on heuristics from logs now = datetime.now().astimezone() cutoff = now - timedelta(days=2) @@ -339,6 +339,7 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]: "occurrence": f"le{now.isoformat()}", }) + sent = 0 for cr_json in next_in_bundle(result): cr = CommunicationRequest(cr_json) # as that message was likely the next-outgoing for the patient, @@ -419,6 +420,13 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]: level='exception' ) + # Flooding system on occasions such as a holiday message to all, + # leads to an overwhelmed system. Restrict the flood by processing + # only throttle_limit per run. + sent += 1 + if sent > throttle_limit: + break + return successes, errors def process_cr(self, cr: CommunicationRequest):