PhoenixAssets.DevServer (PhoenixAssets v0.1.0)

View Source

Tracks supervised dev processes and buffers their output.

Provides runtime controls for the dev processes the DevSupervisor runs: query liveness (status/1), restart or stop a process, and read a recent slice of its output (logs/2). Each MuonTrap.Daemon is configured to route its output here via log_line/2, where it is kept in a small per-process ring buffer.

Summary

Functions

Returns a specification to start this module under a supervisor.

Appends an output line for dev process id. A no-op if the server is down.

Returns the most recent output lines for id (oldest first).

Monitors a daemon so [:phoenix_assets, :dev_server, :stop | :crash] is emitted when it exits. A no-op if the tracker is down.

Restarts the dev process with the given id.

Starts the dev-process tracker.

Liveness of the dev process with the given id.

Stops the dev process with the given id.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

log_line(line, id)

@spec log_line(String.t(), atom()) :: :ok

Appends an output line for dev process id. A no-op if the server is down.

logs(id, opts \\ [])

@spec logs(
  atom(),
  keyword()
) :: [String.t()]

Returns the most recent output lines for id (oldest first).

Returns [] when the tracker is not running.

monitor_daemon(id, pid)

@spec monitor_daemon(atom(), pid()) :: :ok

Monitors a daemon so [:phoenix_assets, :dev_server, :stop | :crash] is emitted when it exits. A no-op if the tracker is down.

restart(id)

@spec restart(atom()) :: {:ok, pid()} | {:error, term()}

Restarts the dev process with the given id.

Returns {:error, :not_running} when the dev supervisor itself is down (production, or dev mode disabled) -- this surface is called from Tidewave and must degrade instead of crashing the caller.

start_link(opts \\ [])

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

Starts the dev-process tracker.

status(id)

@spec status(atom()) :: :running | :restarting | :down | :unknown

Liveness of the dev process with the given id.

stop(id)

@spec stop(atom()) :: :ok | {:error, term()}

Stops the dev process with the given id.

Returns {:error, :not_running} when the dev supervisor itself is down.