Raxol.Core.Runtime.Lifecycle.Shutdown (Raxol v2.9.2)

View Source

Shutdown, cleanup, and registry management helpers for Lifecycle. Extracted from Lifecycle to reduce file size.

Summary

Functions

Cleans up the PluginManager if it is still alive.

Deletes the command registry ETS table if it exists.

Runs fun; when silent? is true, log events from the caller and from pids are dropped until fun returns or exits. Other processes log as usual.

Logs each {label, pid, reason} that stop_process/2 failed on.

Stops a supervised process by PID; no-ops on nil or dead processes.

Functions

cleanup_plugin_manager(arg1, state)

Cleans up the PluginManager if it is still alive.

cleanup_registry_table(arg1, state)

Deletes the command registry ETS table if it exists.

quietly(bool, pids, fun)

@spec quietly(boolean(), [pid()], (-> result)) :: result when result: term()

Runs fun; when silent? is true, log events from the caller and from pids are dropped until fun returns or exits. Other processes log as usual.

On a TTY the Terminal Driver turns Logger off for the session and, when it is stopped, restores the level it found. The Driver is stopped first, so without this whatever the rest of the teardown logs prints on the terminal the Driver has just restored. A primary filter rather than the level: the Driver's restore inside fun must not reopen the window.

Each call installs its own filter, so concurrent teardowns cannot lift each other's silence. The filter belongs to a process that monitors the caller and removes it when fun is done or the caller dies: a killed caller runs no after, and a supervisor's shutdown timeout can kill a Lifecycle mid-teardown.

report_stop_failures(failures)

@spec report_stop_failures([{String.t(), pid(), term()}]) :: :ok

Logs each {label, pid, reason} that stop_process/2 failed on.

stop_process(pid, label)

@spec stop_process(pid() | nil, String.t()) :: :ok | {:error, term()}

Stops a supervised process by PID; no-ops on nil or dead processes.

Returns :ok, or {:error, reason} when the process did not stop cleanly: GenServer.stop/3 exits (it does not raise) when the process crashes in its terminate/2 or overruns the timeout. A process that overruns the timeout is killed before this returns; GenServer.stop/3 leaves it running.

Never exits the caller, so the Lifecycle's ordered teardown goes on to stop the remaining children. Reporting a failure is the caller's (see report_stop_failures/1): on a TTY the teardown runs inside quietly/3.