From ea4ad94780ddc115ff43af55383985d8019409da Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Tue, 10 May 2022 16:46:42 +0200 Subject: [PATCH] add msg send retry after delay --- shiftregister/app/tasks.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/shiftregister/app/tasks.py b/shiftregister/app/tasks.py index 275196f..95fd070 100644 --- a/shiftregister/app/tasks.py +++ b/shiftregister/app/tasks.py @@ -41,11 +41,20 @@ def send_messages(): # those messages will be picked up by the cron send later # once we have decided to continue sending messages @shared_task -def send_message(msgid): +def send_message(msgid, is_retry=False): if not global_preferences["helper__send_sms"]: return with transaction.atomic(): - msg = Message.objects.select_for_update().get(pk=msgid) + msgs = Message.objects.select_for_update().filter(pk=msgid)[:1] + if not msgs: + if not is_retry: + print("message not found, retrying") + send_message.apply_async((msgid, True), countdown=0.2) + return + else: + print(f"message {msgid} not found in retry, giving up") + return + msg = msgs[0] if msg.sent_at: return send(msg)