View Source Paraxial.RateLimit (Paraxial v2.8.0)

Thin wrapper around :ets.update_counter/4 and a clean-up process to act as a rate limiter.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the process that creates and cleans the ETS table.

Link to this section Functions

Link to this function

check_rate(table \\ __MODULE__, key, scale, limit, increment \\ 1)

View Source
@spec check_rate(:ets.table(), key, scale, limit, increment) ::
  {:allow, count} | {:deny, limit}
when key: term(),
     scale: pos_integer(),
     limit: pos_integer(),
     increment: pos_integer(),
     count: pos_integer()

Checks the rate-limit for a key.

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec start_link([
  GenServer.option() | {:table, atom()} | {:clean_period, pos_integer()}
]) ::
  GenServer.on_start()

Starts the process that creates and cleans the ETS table.

Accepts the following options:

  • GenServer.options()
  • :table for the ETS table name, defaults to Elixir.Paraxial.RateLimit
  • :clean_period for how often to perform garbage collection