Skip to content

Commit

Permalink
Adjusted Payload Sent in Callbacks to Services' Endpoints (#1193)
Browse files Browse the repository at this point in the history
* fixed typo

* Updated status_reason and provider fields

* unit test quick fix

* Updated logging statements

---------

Co-authored-by: EvanParish <[email protected]>
  • Loading branch information
k-macmillan and EvanParish authored Mar 31, 2023
1 parent 82d74ed commit d37b3de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 10 additions & 11 deletions app/celery/service_callback_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ def send_delivery_status_to_service(
"notification_type": status_update['notification_type'],
}

if "status_reason" in status_update:
payload['status_reason'] = status_update

if 'provider' in status_update:
payload['provider'] = status_update['provider']
payload['status_reason'] = status_update.get('status_reason')
payload['provider'] = status_update.get('provider', 'pinpoint')

# if the provider payload is found in the status_update object
if 'provider_payload' in status_update:
Expand All @@ -61,20 +58,22 @@ def send_delivery_status_to_service(
except RetryableException as e:
try:
current_app.logger.warning(
f"Retrying: {self.name} failed for {logging_tags}, url {service_callback.url}. "
f"exc: {e}"
"Retrying: %s failed for %s, url %s.", self.name, logging_tags, service_callback.url
)
current_app.logger.exception(e)
self.retry(queue=QueueNames.RETRY)
except self.MaxRetriesExceededError:
current_app.logger.error(
f"Retry: {self.name} has retried the max num of times for {logging_tags}, url "
f"{service_callback.url}. exc: {e}")
"Retry: %s has retried the max num of times for %s, url %s.",
self.name, logging_tags, service_callback.url
)
current_app.logger.exception(e)
raise e
except NonRetryableException as e:
current_app.logger.error(
f"Not retrying: {self.name} failed for {logging_tags}, url: {service_callback.url}. "
f"exc: {e}"
"Not retrying: %s failed for %s, url: %s. ", self.name, logging_tags, service_callback.url
)
current_app.logger.exception(e)
raise e


Expand Down
4 changes: 3 additions & 1 deletion tests/app/celery/test_service_callback_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def test_send_delivery_status_to_service_post_https_request_to_service_with_encr
"created_at": datestr.strftime(DATETIME_FORMAT),
"completed_at": datestr.strftime(DATETIME_FORMAT),
"sent_at": datestr.strftime(DATETIME_FORMAT),
"notification_type": notification_type
"notification_type": notification_type,
"status_reason": None,
"provider": "pinpoint"
}

assert request_mock.call_count == 1
Expand Down

0 comments on commit d37b3de

Please sign in to comment.