Skip to content

Commit

Permalink
Merge e3ed8fa into d27e159
Browse files Browse the repository at this point in the history
  • Loading branch information
minglis committed Sep 30, 2016
2 parents d27e159 + e3ed8fa commit a23a21f
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 129 deletions.
17 changes: 12 additions & 5 deletions app/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
encryption
)
from app.aws import s3
from app.celery.provider_tasks import send_sms_to_provider, send_email_to_provider
from app.celery import provider_tasks
from app.dao.jobs_dao import (
dao_update_job,
dao_get_job_by_id
Expand Down Expand Up @@ -84,7 +84,7 @@ def process_job(job_id):
create_uuid(),
encrypted,
datetime.utcnow().strftime(DATETIME_FORMAT)),
queue='db-sms'
queue='db-sms' if not service.research_mode else 'research-mode'
)

if template.template_type == EMAIL_TYPE:
Expand All @@ -93,7 +93,8 @@ def process_job(job_id):
create_uuid(),
encrypted,
datetime.utcnow().strftime(DATETIME_FORMAT)),
queue='db-email')
queue='db-email' if not service.research_mode else 'research-mode'
)

finished = datetime.utcnow()
job.status = 'finished'
Expand Down Expand Up @@ -129,7 +130,10 @@ def send_sms(self,
created_at, notification, notification_id, service.id, SMS_TYPE, api_key_id, key_type
)
)
send_sms_to_provider.apply_async((service_id, notification_id), queue='send-sms')
provider_tasks.deliver_sms.apply_async(
(notification_id),
queue='send-sms' if not service.research_mode else 'research-mode'
)

current_app.logger.info(
"SMS {} created at {}".format(notification_id, created_at)
Expand Down Expand Up @@ -168,7 +172,10 @@ def send_email(self, service_id,
)
)

send_email_to_provider.apply_async((service_id, notification_id), queue='send-email')
provider_tasks.deliver_email.apply_async(
(notification_id),
queue='send-email' if not service.research_mode else 'research-mode'
)

current_app.logger.info("Email {} created at {}".format(notification_id, created_at))
except SQLAlchemyError as e:
Expand Down
13 changes: 10 additions & 3 deletions app/notifications/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)

register_errors(notifications)
from app.celery.provider_tasks import send_sms_to_provider, send_email_to_provider
from app.celery import provider_tasks


@notifications.route('/notifications/email/ses', methods=['POST'])
Expand Down Expand Up @@ -332,10 +332,17 @@ def persist_notification(
)

try:
research_mode = service.research_mode or key_type == KEY_TYPE_TEST
if notification_type == SMS_TYPE:
send_sms_to_provider.apply_async((str(service.id), str(notification_id)), queue='send-sms')
provider_tasks.deliver_sms.apply_async(
(str(notification_id)),
queue='send-sms' if not research_mode else 'research-mode'
)
if notification_type == EMAIL_TYPE:
send_email_to_provider.apply_async((str(service.id), str(notification_id)), queue='send-email')
provider_tasks.deliver_email.apply_async(
(str(notification_id)),
queue='send-email' if not research_mode else 'research-mode'
)
except Exception as e:
current_app.logger.exception("Failed to send to SQS exception", e)
dao_delete_notifications_and_history_by_id(notification_id)
Expand Down
4 changes: 2 additions & 2 deletions tests/app/celery/test_provider_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


def test_should_have_decorated_tasks_functions():
assert send_sms_to_provider.__wrapped__.__name__ == 'send_sms_to_provider'
assert send_email_to_provider.__wrapped__.__name__ == 'send_email_to_provider'
assert deliver_sms.__wrapped__.__name__ == 'deliver_sms'
assert deliver_email.__wrapped__.__name__ == 'deliver_email'


def test_should_by_10_second_delay_as_default():
Expand Down

0 comments on commit a23a21f

Please sign in to comment.