Registry for flow definitions using an ETS table.
The registry stores flow modules and their metadata, allowing flows to be looked up by module name or slug. This is a GenServer that manages an ETS table for fast concurrent reads.
Usage
# Register a flow
:ok = PgFlow.FlowRegistry.register(MyApp.Flows.ProcessOrder)
# Get a flow definition
{:ok, flow_def} = PgFlow.FlowRegistry.get(MyApp.Flows.ProcessOrder)
{:ok, flow_def} = PgFlow.FlowRegistry.get(:process_order)
# List all flows
flows = PgFlow.FlowRegistry.list()
# Unregister a flow
:ok = PgFlow.FlowRegistry.unregister(MyApp.Flows.ProcessOrder)
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets a flow definition by module or slug.
Lists all registered flows.
Registers a flow module in the registry.
Like register/1, but raises ArgumentError on invalid modules.
Starts the FlowRegistry GenServer.
Unregisters a flow module from the registry.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Gets a flow definition by module or slug.
Examples
{:ok, flow_def} = PgFlow.FlowRegistry.get(MyApp.Flows.ProcessOrder)
{:ok, flow_def} = PgFlow.FlowRegistry.get(:process_order)
{:error, :not_found} = PgFlow.FlowRegistry.get(:unknown_flow)
@spec list() :: [map()]
Lists all registered flows.
Returns a list of flow definitions.
Examples
flows = PgFlow.FlowRegistry.list()
#=> [%{module: MyApp.Flows.ProcessOrder, slug: :process_order, ...}, ...]
@spec register(module()) :: :ok | {:error, {:not_loaded, module()} | {:invalid_flow_module, module()}}
Registers a flow module in the registry.
The flow module must implement the PgFlow.Flow behaviour (via use PgFlow.Flow)
and expose flow metadata via the __pgflow_definition__/0 callback.
Returns :ok on success, {:error, reason} otherwise. Reasons:
{:not_loaded, module}— the module could not be loaded{:invalid_flow_module, module}— the module is loaded but does not implement thePgFlow.Flowbehaviour
Examples
:ok = PgFlow.FlowRegistry.register(MyApp.Flows.ProcessOrder)
{:error, {:invalid_flow_module, Enum}} = PgFlow.FlowRegistry.register(Enum)
@spec register!(module()) :: :ok
Like register/1, but raises ArgumentError on invalid modules.
Starts the FlowRegistry GenServer.
@spec unregister(module()) :: :ok
Unregisters a flow module from the registry.
Examples
:ok = PgFlow.FlowRegistry.unregister(MyApp.Flows.ProcessOrder)