mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Merge pull request #1800 from alphagov/replay-created-emails
Replay emails and sms that are still in created
This commit is contained in:
@@ -25,6 +25,7 @@ def deliver_sms(self, notification_id):
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
current_app.logger.info("Start sending SMS for notification id: {}".format(notification_id))
|
||||
send_to_providers.send_sms_to_provider(notification)
|
||||
except Exception as e:
|
||||
try:
|
||||
@@ -46,6 +47,7 @@ def deliver_email(self, notification_id):
|
||||
notification = notifications_dao.get_notification_by_id(notification_id)
|
||||
if not notification:
|
||||
raise NoResultFound()
|
||||
current_app.logger.info("Start sending email for notification id: {}".format(notification_id))
|
||||
send_to_providers.send_email_to_provider(notification)
|
||||
except InvalidEmailError as e:
|
||||
current_app.logger.exception(e)
|
||||
|
||||
@@ -39,6 +39,7 @@ from app.dao.notifications_dao import (
|
||||
dao_get_count_of_letters_to_process_for_date,
|
||||
dao_get_scheduled_notifications,
|
||||
set_scheduled_notification_to_processed,
|
||||
notifications_not_yet_sent
|
||||
)
|
||||
from app.dao.provider_details_dao import (
|
||||
get_current_provider,
|
||||
@@ -53,7 +54,9 @@ from app.models import (
|
||||
LETTER_TYPE,
|
||||
JOB_STATUS_IN_PROGRESS,
|
||||
JOB_STATUS_READY_TO_SEND,
|
||||
JOB_STATUS_ERROR
|
||||
JOB_STATUS_ERROR,
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE
|
||||
)
|
||||
from app.notifications.process_notifications import send_notification_to_queue
|
||||
from app.celery.tasks import (
|
||||
@@ -535,3 +538,22 @@ def letter_raise_alert_if_no_ack_file_for_zip():
|
||||
current_app.logger.info(
|
||||
"letter ack contains zip that is not for today: {}".format(ack_content_set - zip_file_set)
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(name='replay-created-notifications')
|
||||
@statsd(namespace="tasks")
|
||||
def replay_created_notifications():
|
||||
# if the notification has not be send after 4 hours + 15 minutes, then try to resend.
|
||||
resend_created_notifications_older_than = (60 * 60 * 4) + (60 * 15)
|
||||
for notification_type in (EMAIL_TYPE, SMS_TYPE):
|
||||
notifications_to_resend = notifications_not_yet_sent(
|
||||
resend_created_notifications_older_than,
|
||||
notification_type
|
||||
)
|
||||
|
||||
current_app.logger.info("Sending {} {} notifications "
|
||||
"to the delivery queue because the notification "
|
||||
"status was created.".format(len(notifications_to_resend), notification_type))
|
||||
|
||||
for n in notifications_to_resend:
|
||||
send_notification_to_queue(notification=n, research_mode=n.service.research_mode)
|
||||
|
||||
Reference in New Issue
Block a user