Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2172 - Retry Push for certain HTTP status codes #2266

Merged
merged 110 commits into from
Feb 10, 2025
Merged

Conversation

k-macmillan
Copy link
Member

@k-macmillan k-macmillan commented Jan 23, 2025

Description

issue #2172

The goal of this PR is to move logic to send VEText push notifications into a celery tasks. We added retry logic for the following statuses: 429, 500, 502, 503, 504.

#Changes in This PR

V2 Push Notifications

  • Update status code for service unauthorized from 401 to 403
  • Updated push notification flow:
    • Validates requests before queuing deliver_push and returns V2PushPayload dataclass.
    • Formatted request for VEText using format_for_vetext and returns dict.
    • Validated payload dict sent to deliver_push celery task

Celery Provider Tasks

  • Added deliver_push celery task to handle push notifications using vetext_client, instead of being handled directly by the API.
  • Routed deliver_push to SEND_EMAIL queue.
  • Implemented retry logic with AutoRetryException for transient failures.

VEText Client

  • Created format_for_vetext for formatting VEText Payload
  • Update logic for retryable exceptions - 429, 500, 502, 503, 504 status codes, ConnectionTimeout, ReadTimeout

Config Updates

  • Registered app.celery.provider_tasks in Celery imports.
  • Add VETEXT_USERNAME and VETEXT_PASSWORD to celery task definitions

Internal REST API

  • Added /502 and /sleep endpoints for debugging.

Mobile App Registry

  • Improved error handling: Logs & raises when accessing unregistered apps.

How Has This Been Tested?

Test Happy Path Push 201

Test Happy Path Push Broadcast 201

Test Sad Path VEText Service Not Authorized 403

  • Remove push permissions from service
    Screenshot 2025-02-06 at 10 13 58 AM

  • Confirm 403 from /v2/notification/push when service unauthorized

    Screenshot 2025-02-06 at 10 58 21 AM

Test Sad Path VETex Retrible Failure

Checklist

  • I have assigned myself to this PR
  • PR has an appropriate title: #9999 - What the thing does
  • PR has a detailed description, including links to specific documentation
  • I have added the appropriate labels to the PR.
  • I did not remove any parts of the template, such as checkboxes even if they are not used
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to any documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works. Testing guidelines
  • I have ensured the latest main is merged into my branch and all checks are green prior to review
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • The ticket was moved into the DEV test column when I began testing this change

@k-macmillan k-macmillan changed the title First pass #2172 - Push Celery Migration Jan 24, 2025
@k-macmillan k-macmillan self-assigned this Jan 24, 2025
k-macmillan and others added 23 commits January 24, 2025 13:55
…/test_push_notifications.py::TestValidations::test_required_fields
…-affairs/notification-api into 2172-push-retries
@MackHalliday MackHalliday self-assigned this Jan 30, 2025

if retries < max_retries:
if 'icn' in payload:
payload['icn'] = '<redacted>'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you redact the ICN here, won't the retry attempt to use <redacted> instead of the icn? Or does this just affect the logs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app/internal/rest.py Outdated Show resolved Hide resolved

if retries < max_retries:
if 'icn' in payload:
payload['icn'] = '<redacted>'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question.

Comment on lines 68 to 71
self.logger.info('VEText response: %s', response.json() if response.ok else response.status_code)
self.logger.debug(
'VEText response: %s for payload %s', response.json() if response.ok else response.status_code, payload
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug log duplicates output from the preceding info log. Do we need to log the response json or status code twice in succession? Would including only the payload in the debug output be sufficient?

Copy link

@MackHalliday MackHalliday Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - This make is so much easy for the sake of testing - easy to link . We need the info log for upper environments .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto Cris's question about changing the ICN value to "redacted". That's done twice in this file.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@MackHalliday MackHalliday merged commit 676e641 into main Feb 10, 2025
13 checks passed
@MackHalliday MackHalliday deleted the 2172-push-retries branch February 10, 2025 21:50
@cris-oddball cris-oddball changed the title #2172 - Push Celery Migration #2172 - Retry Push for certain HTTP status codes Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants