feat: retry logic for nvidia session token and adding to cart #347
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
.session_token
is retrieved immediately as called bygenerateSetupAction
, if this fails due to a gateway timeout error it is ok. A loop runs everyNVIDIA_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.session_token
, saving us valuable milliseconds to add the product to our cart. If there is nosession_token
(extremely unlikely), we attempt to get one or throw an error. Finally we try to add the product to our cart up toNVIDIA_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.