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