Packages

ExRated, the OTP GenServer with the naughty name that allows you to rate-limit calls to any service that requires it. For example, rate-limit calls to your favorite API which requires no more than `limit` API calls within a `scale` milliseconds time window.

Current section

18 Versions

Jump to

Compare versions

5 files changed
+27 additions
-19 deletions
  @@ -85,13 +85,13 @@ You can also start the GenServer manually, and pass it custom config, with somet
85 85 Alternatively, you can configure them in your `config/config.exs` (or
86 86 other config) file like
87 87
88 - ```
89 - config :exrated,
90 - timeout: 10_000,
91 - cleanup_rate: 10_000,
92 - persisent: false,
93 - name: :ex_rated,
94 - ets_table_name: :ets_rated_test_buckets
88 + ```elixir
89 + config :ex_rated,
90 + timeout: 10_000,
91 + cleanup_rate: 10_000,
92 + persistent: false,
93 + name: :ex_rated,
94 + ets_table_name: :ets_rated_test_buckets
95 95 ```
96 96
97 97 These args and their defaults are:
  @@ -140,6 +140,13 @@ Basic Bench 10000000 0.89 µs/op
140 140
141 141 ## Changes
142 142
143 + ### v2.0.1
144 +
145 + - Add matrix tests for Elixir/OTP versions for Elixir >= 1.6. [@jechol]
146 + - Remove deprecated `Supervisor.Spec.worker` usage. [@jechol]
147 + - Remove `init/1` from generated docs. [@jechol]
148 + - Update config example in README.md
149 +
143 150 ### v2.0.0
144 151
145 152 - [BREAKING] Fixes #24 (Avoid GenServer Serialization) [@nabaskes, @benwilson512]
  @@ -15,4 +15,4 @@
15 15 {<<"optional">>,false},
16 16 {<<"repository">>,<<"hexpm">>},
17 17 {<<"requirement">>,<<"~> 1.5">>}]]}.
18 - {<<"version">>,<<"2.0.0">>}.
18 + {<<"version">>,<<"2.0.1">>}.
  @@ -21,11 +21,13 @@ defmodule ExRated do
21 21 @doc """
22 22 Starts the ExRated rate limit counter server.
23 23 """
24 - def start_link(args, opts \\ []) do
25 - case args do
26 - [] -> GenServer.start_link(__MODULE__, app_args_with_defaults(), opts)
27 - _ -> GenServer.start_link(__MODULE__, Keyword.merge(app_args_with_defaults(), args), opts)
28 - end
24 + def start_link(args \\ [], opts \\ []) do
25 + GenServer.start_link(__MODULE__, Keyword.merge(app_args_with_defaults(), args), opts)
26 + end
27 +
28 + @doc false
29 + def child_spec(args_opts) do
30 + %{id: __MODULE__, start: {__MODULE__, :start_link, args_opts}}
29 31 end
30 32
31 33
  @@ -111,7 +113,9 @@ defmodule ExRated do
111 113
112 114 ## Server Callbacks
113 115
116 + @doc false
114 117 def init(args) do
118 + Process.flag(:trap_exit, true)
115 119 [
116 120 {:timeout, timeout},
117 121 {:cleanup_rate, cleanup_rate},
  @@ -144,7 +148,7 @@ defmodule ExRated do
144 148 end
145 149
146 150 def handle_cast(_msg, state) do
147 - {:reply, state}
151 + {:noreply, state}
148 152 end
149 153
150 154 def handle_info(:prune, state) do
  @@ -4,12 +4,9 @@ defmodule ExRated.App do
4 4 # See http://elixir-lang.org/docs/stable/elixir/Application.html
5 5 # for more information on OTP Applications
6 6 def start(_type, _args) do
7 - import Supervisor.Spec, warn: false
8 -
9 7 children = [
10 8 # Define workers and child supervisors to be supervised
11 - # worker(ExRated.Worker, [arg1, arg2, arg3])
12 - worker(ExRated, [[], [name: :ex_rated]])
9 + {ExRated, [[], [name: :ex_rated]]}
13 10 ]
14 11
15 12 # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
  @@ -3,7 +3,7 @@ defmodule ExRated.Mixfile do
3 3
4 4 def project do
5 5 [app: :ex_rated,
6 - version: "2.0.0",
6 + version: "2.0.1",
7 7 elixir: "~> 1.6",
8 8 description: description(),
9 9 package: package(),