def send_notifications(self):
self._find_notification_segments()
sent_segments = 0
for notification, segments in self.notification_segments.items():
try:
TwilioSMSHelper(notification, self.client).send()
notification.status = NotificationStatusChoices.SENT
notification.sent_datetime = now()
sent_segments += segments
if sent_segments >= settings.TWILIO_SMS_BATCH_SIZE:
time.sleep(60)
sent_segments = 0
except Exception as e:
if isinstance(e, TwilioAPIConcurrentException):
notification.status = NotificationStatusChoices.PENDING
if isinstance(e, TwilioException):
notification.status_message = str(e)
notification.status = NotificationStatusChoices.ERRORED
raise e
else:
notification.status_message = str(e)
notification.status = NotificationStatusChoices.FAILED
raise e