add msg send retry after delay
This commit is contained in:
parent
ea6f7d2849
commit
ea4ad94780
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue