Forja.Config (Forja v0.4.0)

View Source

Configuration struct for a Forja instance.

Stores validated configuration in :persistent_term for O(1) reads without message passing. Each Forja instance is identified by a unique name.

Fields

  • :name - Atom identifying the instance (required)
  • :repo - Ecto.Repo module (required)
  • :pubsub - Phoenix.PubSub module (required)
  • :oban_name - Oban instance name (default: Oban)
  • :default_queue - Default Oban queue used for event jobs (default: :events)
  • :event_topic_prefix - Prefix for PubSub topics (default: "forja")
  • :handlers - List of modules implementing Forja.Handler (default: [])
  • :dead_letter - Module implementing Forja.DeadLetter (default: nil, optional)
  • :reconciliation - Keyword list for reconciliation settings (default: see below)

Reconciliation defaults

reconciliation: [
  enabled: true,
  interval_minutes: 60,
  threshold_minutes: 15,
  max_retries: 3
]

Summary

Functions

Retrieves the configuration stored in :persistent_term by name.

Creates a new Config struct from a keyword list.

Stores the configuration in :persistent_term indexed by the name field.

Types

t()

@type t() :: %Forja.Config{
  dead_letter: module() | nil,
  default_queue: atom(),
  event_topic_prefix: String.t(),
  handlers: [module()],
  name: atom(),
  oban_name: atom(),
  pubsub: module(),
  reconciliation: keyword(),
  repo: module()
}

Functions

get(name)

@spec get(atom()) :: t()

Retrieves the configuration stored in :persistent_term by name.

Raises ArgumentError if the configuration is not found.

new(opts)

@spec new(keyword()) :: t()

Creates a new Config struct from a keyword list.

Validates that the required fields (:name, :repo, :pubsub) are present. Raises ArgumentError if any required field is missing.

Examples

iex> Forja.Config.new(name: :my_app, repo: MyApp.Repo, pubsub: MyApp.PubSub)
%Forja.Config{name: :my_app, repo: MyApp.Repo, pubsub: MyApp.PubSub, ...}

store(config)

@spec store(t()) :: :ok

Stores the configuration in :persistent_term indexed by the name field.

The key used is {Forja.Config, name}.