-
Notifications
You must be signed in to change notification settings - Fork 7
Drop retry strategy and up cache time #461
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
81e2777
Look for 429 for retries, and add a longer delay for airtable data so…
ingeniumed f9f31ba
Switch the retry mechanism to be an exponential one
ingeniumed d119f27
Change the backoff strategy to exponential
ingeniumed 4cbf964
Remove unused code
ingeniumed 555d5ac
Remove unused code
ingeniumed 581bd6f
Go back to exponential with jitter
ingeniumed 87483a7
Tweak the minimum values
ingeniumed cd782e5
Switch to just exponential, and add a test
ingeniumed 01642aa
Re-enable caching
ingeniumed dab8c2b
Remove the retry logic
ingeniumed 4b4836a
Update the cache time, and add a new test for stale caches
ingeniumed 4f60428
Remove the new test as it's not practical
ingeniumed dbf390a
Update doc
ingeniumed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,7 @@ public static function retry_decider( int $retries, RequestInterface $request, ? | |
|
||
$should_retry = false; | ||
|
||
if ( $response && $response->getStatusCode() >= 500 ) { | ||
if ( $response && ( $response->getStatusCode() >= 500 || $response->getStatusCode() === 429 ) ) { | ||
$should_retry = true; | ||
} | ||
|
||
|
@@ -143,9 +143,15 @@ public static function retry_decider( int $retries, RequestInterface $request, ? | |
* @return int Number of milliseconds to delay. | ||
*/ | ||
public static function retry_delay( int $retries, ?ResponseInterface $response ): int { | ||
// Be default, implement a linear backoff strategy. | ||
$retry_after = $retries; | ||
|
||
// Implement an exponential backoff strategy with jitter, with the delay capped at 10s and a minimum of 1s. | ||
// Full Jitter taken from https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/. | ||
// Given we only retry 3 times, this will really never exceed 8s. | ||
$retry_after_without_jitter = min( 10, 1 * pow( 2, $retries ) ); | ||
$retry_after = wp_rand( 1, $retry_after_without_jitter ); | ||
|
||
// If the response has a Retry-After header, use that value. | ||
// If the value is a date, calculate the difference from now. | ||
// If the value is a number, use that as the delay. | ||
if ( $response instanceof ResponseInterface && $response->hasHeader( 'Retry-After' ) ) { | ||
$retry_after = $response->getHeaderLine( 'Retry-After' ); | ||
|
||
|
@@ -154,6 +160,7 @@ public static function retry_delay( int $retries, ?ResponseInterface $response ) | |
} | ||
} | ||
|
||
// Convert it to milliseconds. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept it this way so that both the calculated value, and the "retry-after" values are converted from s to ms. |
||
$retry_after_ms = (int) $retry_after * 1000; | ||
return apply_filters( 'remote_data_blocks_http_client_retry_delay', $retry_after_ms, $retries, $response ); | ||
} | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added status code 429 here so we retry when we are being rate limited as well.