Sagents.Supervisor (Sagents v0.4.0)

Copy Markdown

Top-level supervisor for Sagents infrastructure.

Starts the process registry, agent dynamic supervisor, and filesystem dynamic supervisor as children under a single supervisor.

Why use this in your application?

OTP shuts down supervision tree children in reverse start order. By adding Sagents.Supervisor to your application's supervision tree after your Repo and PubSub, you ensure that agent processes terminate before Repo and PubSub shut down. This allows agents to persist state and broadcast shutdown events during terminate/2.

Usage

Add Sagents.Supervisor to your application's supervision tree after your Repo, PubSub, and Presence:

# lib/my_app/application.ex
def start(_type, _args) do
  children = [
    MyApp.Repo,
    {Phoenix.PubSub, name: MyApp.PubSub},
    MyAppWeb.Presence,
    Sagents.Supervisor,
    MyAppWeb.Endpoint
  ]

  opts = [strategy: :one_for_one, name: MyApp.Supervisor]
  Supervisor.start_link(children, opts)
end

What it starts

The backend (local vs Horde) is determined by application config:

# Single-node (default — no config needed)
config :sagents, :distribution, :local

# Distributed cluster
config :sagents, :distribution, :horde

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])