ExWapp.RateLimiter (ExWapp v0.1.2)

Copy Markdown View Source

Applies configurable token-bucket throttling before outbound sends.

Global, per-recipient, per-group, and minimum-delay limits are combined into an updated worker state with actionable retry information.

Summary

Types

bucket()

@type bucket() :: %{tokens: float(), last_ms: integer()}

state_data()

@type state_data() :: %{
  global: bucket() | nil,
  per_jid: %{optional(String.t()) => bucket()},
  per_group: %{optional(String.t()) => bucket()},
  last_send_at_ms: integer() | nil
}

Functions

check_and_update(state, jid)

@spec check_and_update(map(), String.t()) :: {:ok, map()} | {:error, term(), map()}

new()

@spec new() :: state_data()