Refactor to make the new send_to_provider methods take a notification not a notification ID.

- Driven by the fact we won't know the type in the API call
- hence we need to load notification earlier , so pass it not the id through to the send task to avoid loading it twice.
This commit is contained in:
Martyn Inglis
2016-09-22 09:16:58 +01:00
parent 991cc884b4
commit 2f36e0dbcf
4 changed files with 33 additions and 44 deletions

View File

@@ -1,6 +1,7 @@
from flask import current_app
from app import notify_celery
from app.dao import notifications_dao
from app.dao.notifications_dao import update_notification_status_by_id
from app.statsd_decorators import statsd
@@ -35,7 +36,8 @@ def retry_iteration_to_delay(retry=0):
@statsd(namespace="tasks")
def deliver_sms(self, notification_id):
try:
send_to_providers.send_sms_to_provider(notification_id)
notification = notifications_dao.get_notification_by_id(notification_id)
send_to_providers.send_sms_to_provider(notification)
except Exception as e:
try:
current_app.logger.error(
@@ -55,7 +57,8 @@ def deliver_sms(self, notification_id):
@statsd(namespace="tasks")
def deliver_email(self, notification_id):
try:
send_to_providers.send_email_response(notification_id)
notification = notifications_dao.get_notification_by_id(notification_id)
send_to_providers.send_email_to_provider(notification)
except Exception as e:
try:
current_app.logger.error(
@@ -71,7 +74,6 @@ def deliver_email(self, notification_id):
update_notification_status_by_id(notification_id, 'technical-failure')
@notify_celery.task(bind=True, name="send-sms-to-provider", max_retries=5, default_retry_delay=5)
@statsd(namespace="tasks")
def send_sms_to_provider(self, service_id, notification_id):