Supervisor

Processes

Start a tree of supervised processes.

In Server.application, put children on the supervisor field: the repo pool, jobs runner, websocket socket, and any [Platform] `supervised` workers. `OneForOne` is the usual strategy (only the failed child restarts).

Supervisor.new OneForOne
    |> Supervisor.add (Repo.supervised repo)
    |> Supervisor.add (Jobs.supervised jobsConfig)
    |> Supervisor.add (Socket.supervised [ mount ])

Child specs come from helpers like Repo.supervised, or from [Supervision] `worker` when you wrap `Actor.start` / `Platform.supervised` yourself. See `examples/03_todo_app` and `examples/15_jobs`.

Types

Builder

type Builder = Builder

A supervision tree that is still being configured.

Examples

Supervisor.new OneForOne : Builder

Strategy

type Strategy
= OneForOne
| OneForAll
| RestForOne

How failures propagate among supervised children.

- OneForOne: restart only the child that failed (most common) - OneForAll: restart every child when one fails - RestForOne: restart the failed child and every child started after it

Examples

OneForOne

Values

new

new : Strategy -> Builder

Start building a supervision tree with the given restart strategy.

Examples

Supervisor.new OneForOne

add

add : ChildSpecification a -> Builder -> Builder

Add a child specification to the tree.

Examples

Supervisor.add (Repo.supervised repo) tree

start

start : Builder -> Result StartError (Started Supervisor)

Start the supervision tree (used by tests and tooling). Server apps usually pass the builder to Server.application instead of calling start yourself.

Examples

Supervisor.start tree