Refactor send_user_reset_password to persist and send message to the notify queue.

The reason for doing this is to ensure the tasks performed for the Notify users are not queued behind a large job, a way to
ensure priority for messages.

5th task for story: https://www.pivotaltracker.com/story/show/135839709
This commit is contained in:
Rebecca Law
2016-12-20 11:55:26 +00:00
parent 813947e7e4
commit a03732472c
3 changed files with 65 additions and 81 deletions

View File

@@ -288,19 +288,22 @@ def send_user_reset_password():
user_to_send_to = get_user_by_email(email['email'])
template = dao_get_template_by_id(current_app.config['PASSWORD_RESET_TEMPLATE_ID'])
message = {
'template': str(template.id),
'template_version': template.version,
'to': user_to_send_to.email_address,
'personalisation': {
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=email['email'],
service_id=current_app.config['NOTIFY_SERVICE_ID'],
personalisation={
'user_name': user_to_send_to.name,
'url': _create_reset_password_url(user_to_send_to.email_address)
}
}
send_email.apply_async([current_app.config['NOTIFY_SERVICE_ID'],
str(uuid.uuid4()),
encryption.encrypt(message),
datetime.utcnow().strftime(DATETIME_FORMAT)], queue='notify')
},
notification_type=EMAIL_TYPE,
api_key_id=None,
key_type=KEY_TYPE_NORMAL
)
send_notification_to_queue(saved_notification, False, queue="notify")
return jsonify({}), 204