Normandy.Agents.Turn.Supervisor (normandy v2.2.0)

View Source

DynamicSupervisor for Turn.Server processes (one per live session).

A crashed session restarts (restart: :transient) and reloads its turn state and memory from the store. See start_link/1 for options.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the supervisor.

Starts a Turn.Server for a session under sup, named through the registry's child_name/2 when it has one.

Stops the session server pid, a child of sup, without a restart. Returns {:error, :not_found} when pid is not a child of sup (it already exited, or another supervisor started it). Used by Normandy.Agents.Turn.Session.delete/1.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()

Starts the supervisor.

Options

  • :name (term/0) - A GenServer.name/0 for the supervisor.

  • :max_restarts (non_neg_integer/0) - Restarts allowed within :max_seconds. The limit is shared by every session under this supervisor; exceeding it stops the supervisor and all of its sessions. The OTP default (3 in 5 seconds) would let a few unrelated session crashes take every session down. The default value is 100.

  • :max_seconds (pos_integer/0) - The window for :max_restarts, in seconds. The default value is 5.

start_server(sup, server_opts)

Starts a Turn.Server for a session under sup, named through the registry's child_name/2 when it has one.

server_opts are checked here, in the caller, before the supervisor starts anything: a bad option raises ArgumentError instead of coming back as the supervisor's {:error, {exception, stacktrace}}.

Returns {:ok, pid}, or:

  • {:error, {:already_started, pid}}: a server for the session is already registered (under a :via name, or found by a self-registering server); route to pid.
  • {:error, :registration_race}: a self-registering server found the session taken, but the holder died before its lookup; start again.
  • {:error, reason}: the registry could not answer that lookup, or the supervisor refused the child.

The session is loaded after the start returns, so a store or template failure is not a start error (the server waits :unavailable).

Options

The options of Normandy.Agents.Turn.Server.start_link/1.

stop_server(sup, pid)

@spec stop_server(:gen_statem.server_ref() | pid(), pid()) ::
  :ok | {:error, :not_found}

Stops the session server pid, a child of sup, without a restart. Returns {:error, :not_found} when pid is not a child of sup (it already exited, or another supervisor started it). Used by Normandy.Agents.Turn.Session.delete/1.