Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whitered/ratekeeper
Ratekeeper is a library for scheduling rate-limited actions.
https://github.com/whitered/ratekeeper
Last synced: 3 months ago
JSON representation
Ratekeeper is a library for scheduling rate-limited actions.
- Host: GitHub
- URL: https://github.com/whitered/ratekeeper
- Owner: whitered
- License: mit
- Created: 2018-07-08T22:39:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-14T03:10:14.000Z (over 6 years ago)
- Last Synced: 2024-09-01T02:38:28.185Z (5 months ago)
- Language: Elixir
- Homepage:
- Size: 21.5 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Rate limiter and rate-limited actions scheduler. (Miscellaneous)
- fucking-awesome-elixir - ratekeeper - Rate limiter and rate-limited actions scheduler. (Miscellaneous)
- awesome-elixir - ratekeeper - Rate limiter and rate-limited actions scheduler. (Miscellaneous)
README
# Ratekeeper
Ratekeeper is a library for scheduling rate-limited actions.
It supports complex rate limits and estimates time left to resetting limits.## Installation
Add `ratekeeper` as dependency in `mix.exs`
``` elixir
def deps do
[{:ratekeeper, "~> 0.2"}]
end
```## Usage
Limits can be set in config:
```elixir
config :ratekeeper, :limits, %{"myapi.org" => [{1000, 5}, {60_000, 100}]}
```
or at runtime:
```elixir
Ratekeeper.add_limit "myapi.org", 1000, 5
Ratekeeper.add_limit "myapi.org", 60_000, 100
```
This sets limits to *5 requests per 1 second* and *100 requests per minute*.Appoint a request to rate limited api:
```elixir
case Ratekeeper.register("myapi.org", 10_000) do
nil ->
raise "Rate limits exceeded, request not allowed in next 10 seconds"
delay ->
:timer.sleep(delay)
MyApi.do_request()
end
```Full documentation can be found at [https://hexdocs.pm/ratekeeper](https://hexdocs.pm/ratekeeper).