Ingot.GracefulShutdown (Ingot v0.1.0)
View SourceDrains LiveView connections before shutdown. Called by Kubernetes preStop hook.
This module ensures graceful shutdown of the Phoenix endpoint by:
- Broadcasting a shutdown message to all connected LiveView clients
- Waiting for active sessions to complete (up to 30 seconds)
- Allowing Kubernetes to terminate the pod cleanly
Usage
In Kubernetes deployment.yaml:
lifecycle:
preStop:
exec:
command: ["/app/bin/ingot", "rpc", "Ingot.GracefulShutdown.drain()"]
Summary
Functions
Returns the count of active LiveView sessions.
Initiates graceful shutdown by broadcasting shutdown message and waiting for connections to drain.
Functions
@spec count_active_sessions() :: non_neg_integer()
Returns the count of active LiveView sessions.
This function counts the number of active LiveView processes. In the current implementation, this returns 0 as LiveView connections are ephemeral and will naturally drain when the endpoint stops accepting new connections.
A production implementation could track active sessions via:
- Phoenix.Tracker for distributed session tracking
- Custom Registry for local process counting
- Endpoint telemetry events for connection metrics
Examples
iex> Ingot.GracefulShutdown.count_active_sessions()
0
@spec drain() :: :ok
Initiates graceful shutdown by broadcasting shutdown message and waiting for connections to drain.
Returns :ok after all connections have drained or the timeout is reached.
Examples
iex> Ingot.GracefulShutdown.drain()
:ok