mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-28 19:59:47 -04:00
- wrap apply_async parameter notification_id in a str() argument
- check if service_callback_api exist before putting tasks on queue - create_service_callback_api in tests before asserting if send_delivery_status_to_service has been called.
This commit is contained in:
@@ -58,7 +58,7 @@ def send_delivery_status_to_service(self, notification_id):
|
||||
response.raise_for_status()
|
||||
except RequestException as e:
|
||||
current_app.logger.warning(
|
||||
"send_inbound_sms_to_service request failed for service_id: {} and url: {}. exc: {}".format(
|
||||
"send_delivery_status_to_service request failed for service_id: {} and url: {}. exc: {}".format(
|
||||
notification_id,
|
||||
service_callback_api.url,
|
||||
e
|
||||
@@ -68,4 +68,4 @@ def send_delivery_status_to_service(self, notification_id):
|
||||
try:
|
||||
self.retry(queue=QueueNames.RETRY)
|
||||
except self.MaxRetriesExceededError:
|
||||
current_app.logger.exception('Retry: send_inbound_sms_to_service has retried the max number of times')
|
||||
current_app.logger.exception('Retry: send_delivery_status_to_service has retried the max number of times')
|
||||
|
||||
@@ -44,12 +44,13 @@ from app.dao.notifications_dao import (
|
||||
dao_update_notifications_for_job_to_sent_to_dvla,
|
||||
dao_update_notifications_by_reference,
|
||||
dao_get_last_notification_added_for_job_id,
|
||||
dao_get_notifications_by_reference
|
||||
dao_get_notifications_by_references
|
||||
)
|
||||
from app.dao.provider_details_dao import get_current_provider
|
||||
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
|
||||
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.dao.service_callback_api_dao import get_service_callback_api_for_service
|
||||
from app.models import (
|
||||
DVLA_RESPONSE_STATUS_SENT,
|
||||
EMAIL_TYPE,
|
||||
@@ -393,9 +394,12 @@ def update_letter_notifications_to_error(self, notification_references):
|
||||
)
|
||||
|
||||
current_app.logger.info("Updated {} letter notifications to technical-failure".format(updated_count))
|
||||
notifications = dao_get_notifications_by_reference(references=notification_references)
|
||||
for notification in notifications:
|
||||
send_delivery_status_to_service.apply_async([notification.id], queue=QueueNames.NOTIFY)
|
||||
notifications = dao_get_notifications_by_references(references=notification_references)
|
||||
# queue callback task only if the service_callback_api exists
|
||||
service_callback_api = get_service_callback_api_for_service(service_id=notifications[0].service_id)
|
||||
if service_callback_api:
|
||||
for notification in notifications:
|
||||
send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.NOTIFY)
|
||||
|
||||
|
||||
def create_dvla_file_contents_for_job(job_id):
|
||||
@@ -477,9 +481,12 @@ def update_letter_notifications_statuses(self, filename):
|
||||
current_app.logger.info(
|
||||
'DVLA file: {filename}, notification updated to {status}: {reference}'.format(
|
||||
filename=filename, status=status, reference=str(update.reference)))
|
||||
notifications = dao_get_notifications_by_reference(references=[update.reference])
|
||||
for notification in notifications:
|
||||
send_delivery_status_to_service.apply_async([notification.id], queue=QueueNames.NOTIFY)
|
||||
notifications = dao_get_notifications_by_references(references=[update.reference])
|
||||
# queue callback task only if the service_callback_api exists
|
||||
service_callback_api = get_service_callback_api_for_service(service_id=notifications[0].service_id)
|
||||
if service_callback_api:
|
||||
for notification in notifications:
|
||||
send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.NOTIFY)
|
||||
|
||||
|
||||
def process_updates_from_file(response_file):
|
||||
|
||||
@@ -460,7 +460,7 @@ def dao_get_notifications_by_to_field(service_id, search_term, statuses=None):
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notifications_by_reference(references):
|
||||
def dao_get_notifications_by_references(references):
|
||||
return Notification.query.filter(
|
||||
Notification.reference.in_(references)
|
||||
).all()
|
||||
|
||||
@@ -10,6 +10,7 @@ from app.clients.email.aws_ses import get_aws_responses
|
||||
from app.dao import (
|
||||
notifications_dao
|
||||
)
|
||||
from app.dao.service_callback_api_dao import get_service_callback_api_for_service
|
||||
from app.celery.statistics_tasks import create_outcome_notification_statistic_tasks
|
||||
from app.notifications.process_client_response import validate_callback_data
|
||||
from app.celery.service_callback_tasks import send_delivery_status_to_service
|
||||
@@ -77,7 +78,7 @@ def process_ses_response(ses_request):
|
||||
)
|
||||
|
||||
create_outcome_notification_statistic_tasks(notification)
|
||||
send_delivery_status_to_service.apply_async([notification.id], queue=QueueNames.NOTIFY)
|
||||
_check_and_queue_callback_task(notification.id, notification.service_id)
|
||||
return
|
||||
|
||||
except KeyError:
|
||||
@@ -92,3 +93,10 @@ def process_ses_response(ses_request):
|
||||
def remove_emails_from_bounce(bounce_dict):
|
||||
for recip in bounce_dict['bouncedRecipients']:
|
||||
recip.pop('emailAddress')
|
||||
|
||||
|
||||
def _check_and_queue_callback_task(notification_id, service_id):
|
||||
# queue callback task only if the service_callback_api exists
|
||||
service_callback_api = get_service_callback_api_for_service(service_id=service_id)
|
||||
if service_callback_api:
|
||||
send_delivery_status_to_service.apply_async([str(notification_id)], queue=QueueNames.NOTIFY)
|
||||
|
||||
@@ -10,6 +10,8 @@ from app.clients.sms.mmg import get_mmg_responses
|
||||
from app.celery.statistics_tasks import create_outcome_notification_statistic_tasks
|
||||
from app.celery.service_callback_tasks import send_delivery_status_to_service
|
||||
from app.config import QueueNames
|
||||
from app.dao.service_callback_api_dao import get_service_callback_api_for_service
|
||||
|
||||
|
||||
sms_response_mapper = {
|
||||
'MMG': get_mmg_responses,
|
||||
@@ -83,8 +85,11 @@ def process_sms_client_response(status, reference, client_name):
|
||||
)
|
||||
|
||||
create_outcome_notification_statistic_tasks(notification)
|
||||
# queue callback task only if the service_callback_api exists
|
||||
service_callback_api = get_service_callback_api_for_service(service_id=notification.service_id)
|
||||
|
||||
send_delivery_status_to_service.apply_async([notification.id], queue=QueueNames.NOTIFY)
|
||||
if service_callback_api:
|
||||
send_delivery_status_to_service.apply_async([str(notification.id)], queue=QueueNames.NOTIFY)
|
||||
|
||||
success = "{} callback succeeded. reference {} updated".format(client_name, reference)
|
||||
return success, errors
|
||||
|
||||
Reference in New Issue
Block a user