A very thin wrapper around Erlang's mnesia, used to provide distributed rate limiting, with little to no configuration and a simple API for developer happiness.
MIT License
A very thin wrapper around Erlang's mnesia used to provide distributed rate limiting, with little to no configuration and a simple API for developer happiness.
Install by adding blackout
to your list of dependencies in mix.exs
:
def deps do
[
{:blackout, "~> 0.1.0"}
]
end
Add blackout
to each umbrella application's mix.exs
the same as above.
defmodule SomeModule.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
{SomeModule.Worker, []}
]
# Your nodes should be connected by this point
connected_nodes = Node.list() ++ [Node.self()]
schema = :my_schema_name
{:ok, _} = Blackout.join_cluster(schema, connected_nodes)
opts = [strategy: :one_for_one, name: SomeModule.Supervisor]
Supervisor.start_link(children, opts)
end
end
iex([email protected])1> schema = :my_schema_name
:my_schema_name
iex([email protected])2> bucket_name = "route_requests"
"route_requests"
iex([email protected])3> allowed_count = 2
2
iex([email protected])4> bucket_expiration = 10_000
10_000
iex([email protected])5> Blackout.check_bucket(schema, bucket_name, allowed_count, bucket_expiration)
{:atomic, {:ok, 10_000}}
iex([email protected])1> schema = :my_schema_name
:my_schema_name
iex([email protected])2> bucket_name = "route_requests"
"route_requests"
iex([email protected])3> Blackout.delete_bucket(schema, bucket_name)
{:atomic, :ok}