- 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:
venusbb
2017-12-04 14:48:23 +00:00
parent 771ce9e2bc
commit 5482ee4fe7
10 changed files with 48 additions and 21 deletions

View File

@@ -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')

View File

@@ -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):