Conjure.Registry (Conjure v0.1.1-alpha)

View Source

In-memory registry of loaded skills.

The Registry provides both a stateful GenServer for OTP applications and pure functions for stateless usage.

GenServer Usage

Add to your supervision tree:

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    children = [
      {Conjure.Registry, name: MyApp.Skills, paths: ["/path/to/skills"]}
    ]

    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

Then access skills anywhere:

skills = Conjure.Registry.list(MyApp.Skills)
skill = Conjure.Registry.get(MyApp.Skills, "pdf")

Stateless Usage

For simpler use cases without a GenServer:

{:ok, skills} = Conjure.load("/path/to/skills")
index = Conjure.Registry.index(skills)
skill = Conjure.Registry.find(index, "pdf")

Options

  • :name - Required. The name to register the GenServer under.
  • :paths - List of paths to load skills from.
  • :reload_interval - Optional. Interval in ms to auto-reload skills.

Summary

Functions

Returns a specification to start this module under a supervisor.

Get the count of registered skills.

Find a skill by name in an index.

Find skills matching a pattern.

Find a skill by name.

Create an index from a list of skills.

Get all registered skills.

Register additional skills with the registry.

Reload skills from configured paths.

Start the registry as a GenServer.

Types

t()

@type t() :: %Conjure.Registry{
  ets_table: :ets.tid() | nil,
  index: %{required(String.t()) => Conjure.Skill.t()},
  name: atom(),
  paths: [Path.t()],
  reload_interval: pos_integer() | nil,
  skills: [Conjure.Skill.t()]
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count(server)

@spec count(GenServer.server()) :: non_neg_integer()

Get the count of registered skills.

find(skill_index, name)

@spec find(%{required(String.t()) => Conjure.Skill.t()}, String.t()) ::
  Conjure.Skill.t() | nil

Find a skill by name in an index.

find_matching(skills, pattern)

@spec find_matching([Conjure.Skill.t()], String.t()) :: [Conjure.Skill.t()]

Find skills matching a pattern.

The pattern can include wildcards (*).

get(server, name)

@spec get(GenServer.server(), String.t()) :: Conjure.Skill.t() | nil

Find a skill by name.

index(skills)

@spec index([Conjure.Skill.t()]) :: %{required(String.t()) => Conjure.Skill.t()}

Create an index from a list of skills.

Returns a map from skill name to skill struct for O(1) lookups.

list(server)

@spec list(GenServer.server()) :: [Conjure.Skill.t()]

Get all registered skills.

register(server, skills)

@spec register(GenServer.server(), [Conjure.Skill.t()]) :: :ok

Register additional skills with the registry.

reload(server)

@spec reload(GenServer.server()) :: :ok | {:error, term()}

Reload skills from configured paths.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start the registry as a GenServer.

Options

  • :name - Required. Name to register under.
  • :paths - List of paths to load skills from (default: [])
  • :reload_interval - Auto-reload interval in ms (optional)
  • :use_ets - Store skills in ETS for concurrent reads (default: true)