Ingot.Components.ComponentRegistry (Ingot v0.1.0)
View SourceManages dynamic loading and caching of pluggable components.
This GenServer loads component modules at runtime based on queue configuration, verifies they implement the required behaviors, and caches them for efficient repeated access.
Component Resolution
- Check cache for queue_id
- If not cached, fetch queue metadata from AnvilClient
- If metadata contains
component_module, load and verify it - If no component_module or loading fails, return DefaultComponent
- Cache the result for future lookups
Usage
# Get component for a queue
{:ok, component} = ComponentRegistry.get_component("queue-123")
# Use the component
component.render_sample(sample, mode: :labeling)
# Clear cache (e.g., after deploying new component version)
ComponentRegistry.clear_cache()
Summary
Functions
Returns a specification to start this module under a supervisor.
Clear all cached components.
Clear cached component for a specific queue.
Get component module for a queue.
Load and verify a component module.
Start the ComponentRegistry GenServer.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_cache() :: :ok
Clear all cached components.
Useful when deploying new component versions or during testing.
Examples
:ok = ComponentRegistry.clear_cache()
@spec clear_cache(queue_id()) :: :ok
Clear cached component for a specific queue.
Examples
:ok = ComponentRegistry.clear_cache("queue-123")
@spec get_component(queue_id()) :: {:ok, component_module()} | {:error, error()}
Get component module for a queue.
Loads and caches the component on first access. Returns DefaultComponent if no custom component is configured or if loading fails.
Examples
{:ok, component} = ComponentRegistry.get_component("queue-123")
component.render_sample(sample, [])
@spec load_component(String.t() | atom()) :: {:ok, component_module()} | {:error, error()}
Load and verify a component module.
Can be called with either a string module name or an atom. Verifies that the module implements both required behaviors.
Examples
{:ok, module} = ComponentRegistry.load_component("MyApp.CustomComponent")
{:ok, module} = ComponentRegistry.load_component(MyApp.CustomComponent)
Start the ComponentRegistry GenServer.
Typically started as part of the application supervision tree.