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

add rate limiter #38

Merged
merged 5 commits into from
Aug 6, 2022
Merged

add rate limiter #38

merged 5 commits into from
Aug 6, 2022

Conversation

il3ven
Copy link
Collaborator

@il3ven il3ven commented Aug 6, 2022

This PR adds rate-limiter for individual endpoints. We can specify the rate limit of each endpoint in workerData.endpoints. Using the package limiter we ensure that the number of calls is less than the limit. In case of missing config for an endpoint the rate limit for it is ignored.

This PR also introduces the option to specify timeout per endpoint. The timeout can be specified in the config (sample config) for an endpoint or it can be overridden in the message.

if (timeoutFromMsg || timeoutFromConfig) {
      signal = AbortSignal.timeout(timeoutFromMsg ?? timeoutFromConfig);
}

Note: I have used limiter 2.0.1 as there is a bug with the latest version which prevents it's usage in ESM modules. (See this issue)

test/api_test.mjs Outdated Show resolved Hide resolved
Copy link
Collaborator

@TimDaub TimDaub left a comment

Choose a reason for hiding this comment

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

great work, stellar pr!

@il3ven
Copy link
Collaborator Author

il3ven commented Aug 6, 2022

great work, stellar pr!

thanks, i am glad to be able to contribute

@il3ven il3ven deleted the 11/config branch August 14, 2022 20:46
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.

2 participants