mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
- Driven by the fact we won't know the type in the API call - hence we need to load notification earlier , so pass it not the id through to the send task to avoid loading it twice.
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from flask import Blueprint, jsonify
|
|
|
|
from app.delivery import send_to_providers
|
|
from app.models import EMAIL_TYPE
|
|
from app.celery import provider_tasks
|
|
from app.dao import notifications_dao
|
|
|
|
delivery = Blueprint('delivery', __name__)
|
|
|
|
from app.errors import register_errors
|
|
|
|
register_errors(delivery)
|
|
|
|
|
|
@delivery.route('/deliver/notification/<uuid:notification_id>', methods=['POST'])
|
|
def send_notification_to_provider(notification_id):
|
|
|
|
notification = notifications_dao.get_notification_by_id(notification_id)
|
|
if not notification:
|
|
return jsonify(notification={"result": "error", "message": "No result found"}), 404
|
|
|
|
if notification.notification_type == EMAIL_TYPE:
|
|
send_response(send_to_providers.send_email_response, provider_tasks.deliver_email, notification_id, 'send-email')
|
|
else:
|
|
send_response(send_to_providers.send_sms_response, provider_tasks.deliver_sms, notification_id, 'send-sms')
|
|
return jsonify({}), 204
|
|
|
|
|
|
def send_response(send_call, task_call, notification, queue):
|
|
try:
|
|
send_call(notification)
|
|
except Exception as e:
|
|
task_call.apply_async((str(notification.id)), queue=queue)
|