sms rate limiting and error reporting
This commit is contained in:
parent
b949c9e37a
commit
afb4aa274d
|
@ -48,3 +48,9 @@ class CancelMin(types.DurationPreference):
|
|||
section = helper
|
||||
name = "min_cancel_time"
|
||||
default = datetime.timedelta(hours=6)
|
||||
|
||||
@global_preferences_registry.register
|
||||
class SMSRate(types.IntegerPreference):
|
||||
section = helper
|
||||
name = "sms_rate"
|
||||
default = 2
|
|
@ -5,6 +5,7 @@ from django.db import transaction
|
|||
from django.utils import timezone
|
||||
from dynamic_preferences.registries import global_preferences_registry
|
||||
from .sipgate.sms import send as send_sms
|
||||
import sentry_sdk
|
||||
|
||||
global_preferences = global_preferences_registry.manager()
|
||||
|
||||
|
@ -28,7 +29,7 @@ def send_messages():
|
|||
print("sms disabled, not sending")
|
||||
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():
|
||||
for msg in msgs:
|
||||
if msg.sent_at:
|
||||
|
@ -37,8 +38,8 @@ def send_messages():
|
|||
send(msg)
|
||||
msg.sent_at = timezone.now()
|
||||
msg.save()
|
||||
except:
|
||||
pass
|
||||
except e:
|
||||
sentry_sdk.capture_exception(e)
|
||||
|
||||
|
||||
# singlemessage so registration links arrive faster.
|
||||
|
|
Loading…
Reference in New Issue