GenServer for plugin lifecycle coordination.
Handles stateful plugin operations that require coordination:
- Loading and unloading plugins
- Enabling and disabling plugins
- Managing plugin runtime state
- File watching for hot reload
- Timer-based operations
Design
This module is the "coordination layer" - it's a GenServer because it needs to:
- Coordinate concurrent plugin operations
- Manage timers for debounced reloads
- Track per-plugin runtime state
Read-only operations should use PluginRegistry directly for better performance.
Usage
# Start lifecycle manager
{:ok, _pid} = PluginLifecycle.start_link([])
# Load a plugin
PluginLifecycle.load(:my_plugin, MyPlugin, %{config: "value"})
# Enable/disable
PluginLifecycle.enable(:my_plugin)
PluginLifecycle.disable(:my_plugin)
# Get runtime state
PluginLifecycle.get_state(:my_plugin)
Summary
Functions
Returns a specification to start this module under a supervisor.
Disables a plugin without unloading it.
Disables file watching.
Enables a loaded plugin.
Enables file watching for plugin hot reload.
Gets the configuration of a plugin.
Gets the runtime state of a plugin.
Gets the status of a plugin.
Lists all plugins with their status.
Loads a plugin module with optional configuration.
Reloads a plugin (unload + load).
Schedules a debounced reload for a plugin.
Updates the runtime state of a plugin.
Unloads a plugin, cleaning up state and unregistering.
Updates plugin configuration.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Disables a plugin without unloading it.
@spec disable_file_watching() :: :ok
Disables file watching.
Enables a loaded plugin.
@spec enable_file_watching([String.t()]) :: :ok
Enables file watching for plugin hot reload.
Gets the configuration of a plugin.
@spec get_state(plugin_id()) :: {:ok, plugin_state()} | {:error, :not_found}
Gets the runtime state of a plugin.
@spec get_status(plugin_id()) :: plugin_status() | nil
Gets the status of a plugin.
@spec list_with_status() :: [{plugin_id(), plugin_status()}]
Lists all plugins with their status.
Loads a plugin module with optional configuration.
Registers in PluginRegistry and initializes lifecycle state.
Reloads a plugin (unload + load).
@spec schedule_reload(plugin_id(), non_neg_integer()) :: :ok
Schedules a debounced reload for a plugin.
Useful for file-watching scenarios where multiple changes should trigger only one reload.
@spec set_state(plugin_id(), plugin_state()) :: :ok | {:error, :not_found}
Updates the runtime state of a plugin.
Unloads a plugin, cleaning up state and unregistering.
Updates plugin configuration.