Helper functions for common session management tasks.
This module provides convenient functions for batch operations, session health checks, and common patterns.
Summary
Functions
Broadcast a message to all active sessions.
Create a session with automatic retry on rate limit.
Find sessions by pattern matching on session ID.
Gets the session module for a given process PID.
Safely call a session with automatic retry on timeout.
Get health status for all sessions.
Start sessions for multiple session IDs in parallel.
Terminate multiple sessions in parallel.
Functions
@spec broadcast_all(any()) :: :ok
Broadcast a message to all active sessions.
Examples
iex> Phoenix.SessionProcess.Helpers.broadcast_all({:system_message, "Maintenance in 5 minutes"})
:ok
@spec create_session_with_retry(binary(), module() | nil, any() | nil, integer()) :: {:ok, pid()} | {:error, term()}
Create a session with automatic retry on rate limit.
Examples
iex> Phoenix.SessionProcess.Helpers.create_session_with_retry("session_123")
{:ok, #PID<0.123.0>}
Find sessions by pattern matching on session ID.
Examples
iex> Phoenix.SessionProcess.Helpers.find_sessions_by_pattern(~r/user_.*/)
["user_123", "user_456"]
Gets the session module for a given process PID.
Safely call a session with automatic retry on timeout.
Examples
iex> Phoenix.SessionProcess.Helpers.safe_call("session_123", :get_user, 3)
{:ok, %User{}}
Get health status for all sessions.
Examples
iex> Phoenix.SessionProcess.Helpers.session_health()
%{healthy: 10, crashed: 0, total: 10}
Start sessions for multiple session IDs in parallel.
Examples
iex> Phoenix.SessionProcess.Helpers.start_sessions(["session1", "session2"])
[{"session1", {:ok, #PID<0.123.0>}}, {"session2", {:ok, #PID<0.124.0>}}]
Terminate multiple sessions in parallel.
Examples
iex> Phoenix.SessionProcess.Helpers.terminate_sessions(["session1", "session2"])
[{"session1", :ok}, {"session2", {:error, :not_found}}]