Skip to content

LG-9433: Create USPS auth token refresh job#8721

Merged
night-jellyfish merged 14 commits intomainfrom
brittany/9433-usps-refresh-job-take-two
Jul 7, 2023
Merged

LG-9433: Create USPS auth token refresh job#8721
night-jellyfish merged 14 commits intomainfrom
brittany/9433-usps-refresh-job-take-two

Conversation

@night-jellyfish
Copy link
Contributor

@night-jellyfish night-jellyfish commented Jul 5, 2023

🎫 Ticket

LG-9433

🛠 Summary of changes

Right now, the responsibility for renewing the authentication token lies
with the methods calling out to the USPS API for any reason. This can
delay requests to, for example, search for nearby post offices, as they
have to first do the authentication and then do the work.

Creating a USPS authentication token refresh job takes the
responsibility away from the other calls to the API. They still have the
logic and ability to do so as a failsafe in case all the refresh jobs
fail, but if the jobs are working properly they should never need to
make the call.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Connect to the USPS API locally and request a token
  • Deploy to the sandbox environment and watch to see analytics come through in AWS to make sure the job is working
  • Deploy through staging or production and watch in New Relic to see if the spikes mentioned in this Slack conversation are gone, to make sure the refresh token job is working as expected

@night-jellyfish night-jellyfish requested review from a team and gina-yamada July 5, 2023 16:42
@night-jellyfish night-jellyfish force-pushed the brittany/9433-usps-refresh-job-take-two branch from aa710f3 to 8ea0416 Compare July 6, 2023 18:13
Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

I think this is sufficient and functionally correct, but I highly recommend implementing the changes I suggested before merging.

Brittany Greaner and others added 14 commits July 7, 2023 13:56
[LG-9433](https://cm-jira.usa.gov/browse/LG-9433)

Right now, the responsibility for renewing the authentication token lies
with the methods calling out to the USPS API for any reason. This can
delay requests to, for example, search for nearby post offices, as they
have to first do the authentication and then do the work.

Creating a USPS authentication token refresh job takes the
responsibility away from the other calls to the API. They still have the
logic and ability to do so as a failsafe in case all the refresh jobs
fail, but if the jobs are working properly they should never need to
make the call.

Most of the times the job runs (every 5 minutes) it should just find a
token in the cache and then stop. But if the token is under 7 minutes
from expiration, then it will do the work of requesting a new token.

We also added a stubbed method for testing errored requests.

Tested in the Joy Sandbox successfully.
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@night-jellyfish night-jellyfish force-pushed the brittany/9433-usps-refresh-job-take-two branch from 7b5c965 to 58a5459 Compare July 7, 2023 18:56
@night-jellyfish night-jellyfish merged commit abb03e5 into main Jul 7, 2023
@night-jellyfish night-jellyfish deleted the brittany/9433-usps-refresh-job-take-two branch July 7, 2023 19:22
This was referenced Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants