Celery task to send the sms verify code.

Each celery task will use it's own queue.
This commit is contained in:
Rebecca Law
2016-02-17 15:41:33 +00:00
parent d6bea65626
commit d022d036dc
7 changed files with 57 additions and 18 deletions

View File

@@ -30,3 +30,13 @@ def send_sms(service_id, notification_id, encrypted_notification):
except SQLAlchemyError as e:
current_app.logger.debug(e)
@notify_celery.task(name='send-sms-code')
def send_sms_code(encrypted_notification):
notification = encryption.decrypt(encrypted_notification)
try:
twilio_client.send_sms(notification['to'], notification['secret_code'])
except TwilioClientException as e:
current_app.logger.debug(e)

View File

@@ -2,6 +2,8 @@ from datetime import datetime
from flask import (jsonify, request, abort, Blueprint, current_app)
from sqlalchemy.exc import DataError
from sqlalchemy.orm.exc import NoResultFound
from app import encryption
from app.dao.services_dao import get_model_services
from app.aws_sqs import add_notification_to_queue
from app.dao.users_dao import (
@@ -18,7 +20,7 @@ from app.schemas import (
user_schema, users_schema, service_schema, services_schema,
request_verify_code_schema, user_schema_load_json)
from app import api_user
from app.celery.tasks import send_sms_code
user = Blueprint('user', __name__)
@@ -135,8 +137,8 @@ def send_user_code(user_id):
create_user_code(user, secret_code, verify_code.get('code_type'))
if verify_code.get('code_type') == 'sms':
mobile = user.mobile_number if verify_code.get('to', None) is None else verify_code.get('to')
notification = {'to': mobile, 'content': secret_code}
add_notification_to_queue(api_user['client'], 'admin', 'sms', notification)
notification = {'to': mobile, 'secret_code': secret_code}
send_sms_code.apply_async([encryption.encrypt(notification)], queue='sms_code')
elif verify_code.get('code_type') == 'email':
email = user.email_address if verify_code.get('to', None) is None else verify_code.get('to')
notification = {