Orchestrates the lifecycle of all gateway shards.
Inspired by JDA's DefaultShardManager but built on OTP primitives:
- Fetches
/gateway/botfor recommended shard count andmax_concurrency - Launches shards via
DynamicSupervisorwith staggered timing - Monitors shards and auto-reconnects with exponential backoff + jitter
- Stores
total_shardsin:persistent_termfor O(1) guild→shard routing
Configuration
config :eda, shards: :auto # use Discord's recommended count (default)
config :eda, shards: 4 # fixed 4 shards (0..3)
config :eda, shards: {0..1, 4} # this node handles shards 0,1 out of 4 total
Summary
Functions
Returns a specification to start this module under a supervisor.
Forces a shard to reconnect.
Returns the number of launched shards.
Computes which shard owns a guild. Pure function — no GenServer call.
Returns the status of a shard.
Returns a map with shard statuses and session limit info.
Returns the total number of shards.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec reconnect(non_neg_integer()) :: :ok
Forces a shard to reconnect.
@spec shard_count() :: non_neg_integer()
Returns the number of launched shards.
@spec shard_for_guild(integer() | String.t()) :: non_neg_integer()
Computes which shard owns a guild. Pure function — no GenServer call.
Uses :persistent_term for O(1) access to total_shards.
@spec shard_status(non_neg_integer()) :: :launching | :connected | :disconnected | nil
Returns the status of a shard.
@spec status() :: map()
Returns a map with shard statuses and session limit info.
@spec total_shards() :: non_neg_integer()
Returns the total number of shards.