Solaris.RateLimiter (Solaris v1.0.0)

Copy Markdown View Source

Client-side rate limiter built on Hammer's ETS backend.

Prevents hitting the Solaris API's server-side rate limits (HTTP 429) by throttling outgoing requests at the application level. Uses a sliding-window token-bucket algorithm.

Configuration

config :solaris,
  rate_limit_scale_ms: 1_000,  # 1-second window
  rate_limit_limit: 100        # max 100 requests per window

Usage

Solaris.Client does not call this automatically — it is intended for higher-level wrappers that want proactive throttling rather than reactive retry.

case Solaris.RateLimiter.check() do
  :ok -> proceed()
  {:error, :rate_limited} -> wait_and_retry()
end

Summary

Functions

Checks and increments the rate-limit counter for the current window.

Returns a specification to start this module under a supervisor.

Returns current request count, limit, and remaining capacity.

Functions

check()

@spec check() :: :ok | {:error, :rate_limited}

Checks and increments the rate-limit counter for the current window.

Returns :ok when within limits, {:error, :rate_limited} when exhausted. Fails open if Hammer is unavailable (ETS not started, etc.).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

status()

@spec status() :: %{
  count: non_neg_integer(),
  limit: non_neg_integer(),
  remaining: non_neg_integer()
}

Returns current request count, limit, and remaining capacity.