2
0
Fork 0

sms rate limiting and error reporting

This commit is contained in:
Andreas (@xAndy) Zimmermann 2022-05-17 17:39:40 +02:00
parent b949c9e37a
commit afb4aa274d
2 changed files with 10 additions and 3 deletions

View File

@ -48,3 +48,9 @@ class CancelMin(types.DurationPreference):
section = helper section = helper
name = "min_cancel_time" name = "min_cancel_time"
default = datetime.timedelta(hours=6) default = datetime.timedelta(hours=6)
@global_preferences_registry.register
class SMSRate(types.IntegerPreference):
section = helper
name = "sms_rate"
default = 2

View File

@ -5,6 +5,7 @@ from django.db import transaction
from django.utils import timezone from django.utils import timezone
from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.registries import global_preferences_registry
from .sipgate.sms import send as send_sms from .sipgate.sms import send as send_sms
import sentry_sdk
global_preferences = global_preferences_registry.manager() global_preferences = global_preferences_registry.manager()
@ -28,7 +29,7 @@ def send_messages():
print("sms disabled, not sending") print("sms disabled, not sending")
return return
msgs = Message.objects.select_for_update().filter(sent_at__isnull=True) msgs = Message.objects.select_for_update().filter(sent_at__isnull=True)[:global_preferences['helper__sms_rate']*2]
with transaction.atomic(): with transaction.atomic():
for msg in msgs: for msg in msgs:
if msg.sent_at: if msg.sent_at:
@ -37,8 +38,8 @@ def send_messages():
send(msg) send(msg)
msg.sent_at = timezone.now() msg.sent_at = timezone.now()
msg.save() msg.save()
except: except e:
pass sentry_sdk.capture_exception(e)
# singlemessage so registration links arrive faster. # singlemessage so registration links arrive faster.