mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
Some minor refactoring.
- Updated notifications_dao.update_notification_status_by_id with an optional parameter to set the sent_by, this will eliminate a separate update to notifcaitons. - Added the callback url to the log message, that way we can see if it's the same url failing. - Stop sending the status callbacks for PENDING status.
This commit is contained in:
@@ -97,8 +97,9 @@ def _send_data_to_service_callback_api(self, data, service_callback_url, token,
|
||||
self.retry(queue=QueueNames.RETRY)
|
||||
except self.MaxRetriesExceededError:
|
||||
current_app.logger.error(
|
||||
"Retry: {} has retried the max num of times for notification: {}".format(
|
||||
"Retry: {} has retried the max num of times for callback url {} and notification_id: {}".format(
|
||||
function_name,
|
||||
service_callback_url,
|
||||
notification_id
|
||||
)
|
||||
)
|
||||
|
||||
@@ -143,7 +143,7 @@ def _update_notification_status(notification, status):
|
||||
|
||||
@statsd(namespace="dao")
|
||||
@transactional
|
||||
def update_notification_status_by_id(notification_id, status):
|
||||
def update_notification_status_by_id(notification_id, status, sent_by=None):
|
||||
notification = Notification.query.with_lockmode("update").filter(
|
||||
Notification.id == notification_id,
|
||||
or_(
|
||||
@@ -158,7 +158,8 @@ def update_notification_status_by_id(notification_id, status):
|
||||
|
||||
if notification.international and not country_records_delivery(notification.phone_prefix):
|
||||
return None
|
||||
|
||||
if not notification.sent_by and sent_by:
|
||||
notification.sent_by = sent_by
|
||||
return _update_notification_status(
|
||||
notification=notification,
|
||||
status=status
|
||||
|
||||
@@ -15,6 +15,7 @@ from app.celery.service_callback_tasks import (
|
||||
from app.config import QueueNames
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
from app.dao.service_callback_api_dao import get_service_delivery_status_callback_api_for_service
|
||||
from app.models import NOTIFICATION_PENDING
|
||||
|
||||
sms_response_mapper = {
|
||||
'MMG': get_mmg_responses,
|
||||
@@ -74,7 +75,11 @@ def process_sms_client_response(status, provider_reference, client_name):
|
||||
|
||||
def _process_for_status(notification_status, client_name, provider_reference):
|
||||
# record stats
|
||||
notification = notifications_dao.update_notification_status_by_id(provider_reference, notification_status)
|
||||
notification = notifications_dao.update_notification_status_by_id(
|
||||
notification_id=provider_reference,
|
||||
status=notification_status,
|
||||
sent_by=client_name.lower()
|
||||
)
|
||||
if not notification:
|
||||
current_app.logger.warning("{} callback failed: notification {} either not found or already updated "
|
||||
"from sending. Status {}".format(client_name,
|
||||
@@ -84,9 +89,6 @@ def _process_for_status(notification_status, client_name, provider_reference):
|
||||
|
||||
statsd_client.incr('callback.{}.{}'.format(client_name.lower(), notification_status))
|
||||
|
||||
if not notification.sent_by:
|
||||
set_notification_sent_by(notification, client_name.lower())
|
||||
|
||||
if notification.sent_at:
|
||||
statsd_client.timing_with_dates(
|
||||
'callback.{}.elapsed-time'.format(client_name.lower()),
|
||||
@@ -94,13 +96,13 @@ def _process_for_status(notification_status, client_name, provider_reference):
|
||||
notification.sent_at
|
||||
)
|
||||
|
||||
# queue callback task only if the service_callback_api exists
|
||||
service_callback_api = get_service_delivery_status_callback_api_for_service(service_id=notification.service_id)
|
||||
|
||||
if service_callback_api:
|
||||
encrypted_notification = create_delivery_status_callback_data(notification, service_callback_api)
|
||||
send_delivery_status_to_service.apply_async([str(notification.id), encrypted_notification],
|
||||
queue=QueueNames.CALLBACKS)
|
||||
if notification_status != NOTIFICATION_PENDING:
|
||||
service_callback_api = get_service_delivery_status_callback_api_for_service(service_id=notification.service_id)
|
||||
# queue callback task only if the service_callback_api exists
|
||||
if service_callback_api:
|
||||
encrypted_notification = create_delivery_status_callback_data(notification, service_callback_api)
|
||||
send_delivery_status_to_service.apply_async([str(notification.id), encrypted_notification],
|
||||
queue=QueueNames.CALLBACKS)
|
||||
|
||||
success = "{} callback succeeded. reference {} updated".format(client_name, provider_reference)
|
||||
return success
|
||||
|
||||
Reference in New Issue
Block a user