Do not abort SMS send task if one fails

pull/1/head
Luca 3 years ago
parent 7a9e51704d
commit 48cb7d98bd

@ -27,13 +27,18 @@ def send_messages():
if not global_preferences["helper__send_sms"]:
print("sms disabled, not sending")
return
msgs = Message.objects.select_for_update().filter(sent_at__isnull=True)
with transaction.atomic():
for msg in Message.objects.select_for_update().filter(sent_at__isnull=True):
for msg in msgs:
if msg.sent_at:
continue
try:
send(msg)
msg.sent_at = timezone.now()
msg.save()
except:
pass
# singlemessage so registration links arrive faster.
@ -44,30 +49,35 @@ def send_messages():
def send_message(msgid, is_retry=False):
if not global_preferences["helper__send_sms"]:
return
try:
with transaction.atomic():
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]
msg = Message.objects.select_for_update().get(pk=msgid)
if msg.sent_at:
return
send(msg)
msg.sent_at = timezone.now()
msg.save()
except Message.DoesNotExist:
if not is_retry:
print("message not found, retrying")
send_message.apply_async((msgid, True), countdown=0.2)
else:
print(f"message {msgid} not found in retry, giving up")
@shared_task
def send_reminders():
with transaction.atomic():
for reg in ShiftRegistration.objects.select_for_update().filter(
regs = ShiftRegistration.objects.select_for_update().filter(
reminder_sent=False,
shift__start_at__lte=timezone.now()
+ global_preferences["helper__reminder_time"],
):
)
with transaction.atomic():
for reg in regs:
if reg.reminder_sent:
continue
try:
reg.send_reminder()
except:
pass

Loading…
Cancel
Save