-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix(data-layer): beaconchain 429 rate limit resilience #17832
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 all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * Shared retry.fetch configuration for all data-layer fetchers. | ||
| * | ||
| * Uses Trigger.dev's built-in retry.fetch which automatically handles | ||
| * 429 (rate-limit) and 5xx (server error) responses with exponential backoff. | ||
| */ | ||
| import { retry } from "@trigger.dev/sdk/v3" | ||
|
|
||
| const RETRY_BY_STATUS = { | ||
| "429": { | ||
| strategy: "backoff" as const, | ||
| maxAttempts: 2, | ||
| }, | ||
| "500-599": { | ||
| strategy: "backoff" as const, | ||
| maxAttempts: 2, | ||
| }, | ||
| } | ||
|
|
||
| /** | ||
| * Drop-in replacement for `fetch()` with built-in 429 and 5xx retry. | ||
| * Delegates to Trigger.dev's `retry.fetch` under the hood. | ||
| */ | ||
| export function fetchRetry( | ||
| url: string | URL, | ||
| init?: RequestInit | ||
| ): Promise<Response> { | ||
| return retry.fetch(url, { | ||
| ...init, | ||
| retry: { byStatus: RETRY_BY_STATUS }, | ||
| }) | ||
| } |
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 |
|---|---|---|
|
|
@@ -86,10 +86,10 @@ const DAILY: TaskDef[] = [ | |
| [KEYS.EVENTS, fetchEvents], | ||
| [KEYS.DEVELOPER_TOOLS, fetchDeveloperTools], | ||
| [KEYS.TRANSLATION_GLOSSARY, fetchTranslationGlossary], | ||
| [KEYS.BEACONCHAIN, fetchBeaconChain], | ||
|
Member
Author
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. most important change, from hourly to daily |
||
| ] | ||
|
|
||
| const HOURLY: TaskDef[] = [ | ||
| [KEYS.BEACONCHAIN, fetchBeaconChain], | ||
| [KEYS.BLOBSCAN_STATS, fetchBlobscanStats], | ||
| [KEYS.ETHEREUM_MARKETCAP, fetchEthereumMarketcap], | ||
| [KEYS.ETHEREUM_STABLECOINS_MCAP, fetchEthereumStablecoinsMcap], | ||
|
|
@@ -104,11 +104,7 @@ function createDataTask([key, fetchFn]: TaskDef) { | |
| return task({ | ||
| id: key, | ||
| retry: { | ||
| maxAttempts: 3, | ||
| factor: 2, | ||
| minTimeoutInMs: 2000, | ||
| maxTimeoutInMs: 30000, | ||
| randomize: true, | ||
| maxAttempts: 2, | ||
| }, | ||
| catchError: async ({ error }) => { | ||
| logger.error(`[${key}] failed`, { error }) | ||
|
|
||
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
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.
Worth double-checking: with this sleep removed, the ethstore fetch fires immediately after the epoch fetch. If beaconcha.in enforces 1 req/sec, the second call will routinely 429 and depend on
fetchRetrybackoff to recover. We sure this will work as expected?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.
Yes, tested. Its already working as expected.