Pass sender_id argument to tasks

Started passing `sender_id` to the `save_email`, `save_sms` and
`process_job` tasks, with a default value of `None`.

If `sender_id` is provided, the `save_email` and `save_sms` tasks will
use it to determine the reply-to email address or the SMS sender for the
notifications in the job. The `process_job` task will start using the
value in another commit.
This commit is contained in:
Katie Smith
2018-11-01 17:00:44 +00:00
parent 4b23075488
commit 30fe41fd43
2 changed files with 80 additions and 6 deletions

View File

@@ -45,7 +45,9 @@ from app.dao.notifications_dao import (
dao_get_notification_by_reference,
)
from app.dao.provider_details_dao import get_current_provider
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
from app.dao.templates_dao import dao_get_template_by_id
from app.exceptions import DVLAException, NotificationTechnicalFailureException
@@ -75,7 +77,7 @@ from app.utils import convert_utc_to_bst
@notify_celery.task(name="process-job")
@statsd(namespace="tasks")
def process_job(job_id):
def process_job(job_id, sender_id=None):
start = datetime.utcnow()
job = dao_get_job_by_id(job_id)
@@ -181,11 +183,17 @@ def __sending_limits_for_job_exceeded(service, job, job_id):
def save_sms(self,
service_id,
notification_id,
encrypted_notification):
encrypted_notification,
sender_id=None):
notification = encryption.decrypt(encrypted_notification)
service = dao_fetch_service_by_id(service_id)
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
if sender_id:
reply_to_text = dao_get_service_sms_senders_by_id(service_id, sender_id).sms_sender
else:
reply_to_text = template.get_reply_to_text()
if not service_allowed_to_send_to(notification['to'], service, KEY_TYPE_NORMAL):
current_app.logger.debug(
"SMS {} failed as restricted service".format(notification_id)
@@ -206,7 +214,7 @@ def save_sms(self,
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
notification_id=notification_id,
reply_to_text=template.get_reply_to_text()
reply_to_text=reply_to_text
)
provider_tasks.deliver_sms.apply_async(
@@ -230,12 +238,18 @@ def save_sms(self,
def save_email(self,
service_id,
notification_id,
encrypted_notification):
encrypted_notification,
sender_id=None):
notification = encryption.decrypt(encrypted_notification)
service = dao_fetch_service_by_id(service_id)
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
if sender_id:
reply_to_text = dao_get_reply_to_by_id(service_id, sender_id).email_address
else:
reply_to_text = template.get_reply_to_text()
if not service_allowed_to_send_to(notification['to'], service, KEY_TYPE_NORMAL):
current_app.logger.info("Email {} failed as restricted service".format(notification_id))
return
@@ -254,7 +268,7 @@ def save_email(self,
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
notification_id=notification_id,
reply_to_text=template.get_reply_to_text()
reply_to_text=reply_to_text
)
provider_tasks.deliver_email.apply_async(