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

feat: retry logic for nvidia session token and adding to cart #347

Merged
merged 1 commit into from Sep 27, 2020

Conversation

andrewmackrodt
Copy link
Contributor

@andrewmackrodt andrewmackrodt commented Sep 27, 2020

The existing behaviour for obtaining a session_token and adding to cart assumes a best case scenario, i.e. nvidia's site is not overloaded and requests will succeed on the first try. We know that requests often timeout when there is a 3080/3090 drop so this PR aims to improve the entire process by optimizing when a session is retrieved and retrying the add to cart process.

Note: all behaviour only applies if OPEN_BROWSER=true.

  1. The session_token is retrieved immediately as called by generateSetupAction, if this fails due to a gateway timeout error it is ok. A loop runs every NVIDIA_SESSION_TTL ms to renew the token, defaulting to 60 sec. Tokens should persist throughout the entire session but it's not clear how long they're valid for so we call the endpoint often to hint that we're still active.
  2. When stock is available we should already have a session_token, saving us valuable milliseconds to add the product to our cart. If there is no session_token (extremely unlikely), we attempt to get one or throw an error. Finally we try to add the product to our cart up to NVIDIA_ADD_TO_CART_ATTEMPTS times, defaulting to 10. I've determined 10 to be a sane default value but we may want to increase it. Currently there is no delay between retrying requests, maybe this is something we want to support for large values.
  3. Assuming 1 & 2 are successful, the cart redirect URL is opened in the user's browser as normal.

Copy link
Owner

@jef jef left a comment

Choose a reason for hiding this comment

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

Sweet! Thanks for bringing this back in.

@jef jef changed the title feat: add retry logic for handling nvidia session token and adding to cart feat: retry logic for nvidia session token and adding to cart Sep 27, 2020
@jef jef merged commit 1bac1b9 into jef:main Sep 27, 2020
@jef
Copy link
Owner

jef commented Sep 27, 2020

I've determined 10 to be a sane default value but we may want to increase it.

Some would say 10000 is sane 😆

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.

None yet

2 participants