Add optional queue param to send_notification_to_queue

We want to use this function for sending internal notifications to a different
queue.
This commit is contained in:
Jenny Duckett
2016-12-09 12:10:42 +00:00
parent 32a21bfd3a
commit d5d079a150
2 changed files with 30 additions and 23 deletions

View File

@@ -70,19 +70,22 @@ def persist_notification(template_id,
return notification
def send_notification_to_queue(notification, research_mode):
try:
research_mode = research_mode or notification.key_type == KEY_TYPE_TEST
def send_notification_to_queue(notification, research_mode, queue=None):
if research_mode or notification.key_type == KEY_TYPE_TEST:
queue = 'research-mode'
elif not queue:
if notification.notification_type == SMS_TYPE:
provider_tasks.deliver_sms.apply_async(
[str(notification.id)],
queue='send-sms' if not research_mode else 'research-mode'
)
queue = 'send-sms'
if notification.notification_type == EMAIL_TYPE:
provider_tasks.deliver_email.apply_async(
[str(notification.id)],
queue='send-email' if not research_mode else 'research-mode'
)
queue = 'send-email'
if notification.notification_type == SMS_TYPE:
deliver_task = provider_tasks.deliver_sms
if notification.notification_type == EMAIL_TYPE:
deliver_task = provider_tasks.deliver_email
try:
deliver_task.apply_async([str(notification.id)], queue=queue)
except Exception as e:
current_app.logger.exception(e)
dao_delete_notifications_and_history_by_id(notification.id)