PgFlow.FlowRegistry (PgFlow v0.1.0)

Copy Markdown View Source

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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(flow_module_or_slug)

@spec get(module() | atom()) :: {:ok, map()} | {:error, :not_found}

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)

list()

@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, ...}, ...]

register(flow_module)

@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 the PgFlow.Flow behaviour

Examples

:ok = PgFlow.FlowRegistry.register(MyApp.Flows.ProcessOrder)
{:error, {:invalid_flow_module, Enum}} = PgFlow.FlowRegistry.register(Enum)

register!(flow_module)

@spec register!(module()) :: :ok

Like register/1, but raises ArgumentError on invalid modules.

start_link(opts \\ [])

Starts the FlowRegistry GenServer.

unregister(flow_module)

@spec unregister(module()) :: :ok

Unregisters a flow module from the registry.

Examples

:ok = PgFlow.FlowRegistry.unregister(MyApp.Flows.ProcessOrder)