Arrea.Config (Arrea v2.2.0)

Copy Markdown View Source

Configuration for the Arrea engine.

Configuration priority

Arrea as a library (lowest to highest priority)

  1. @default — Baseline values compiled in this module. Always present.
  2. config :arrea, :engine, [...] in the consumer project's config.exs — overrides the defaults at compile time through OTP's Application env.
  3. Arrea.Config.set/2 at runtime — persists in the current VM session via Application.put_env. Overrides static config.
  4. Options passed directly to the functions (execute/2, run/2, etc.) — highest priority. Callers should check opts before falling back to Config.get/2.

Note on "Arrea's own config"

As an Elixir/OTP library, Arrea cannot have its own config files with higher priority than the consumer project — the consumer project always wins in the Application env hierarchy. The @default in this module is the only "own" Arrea configuration, and it acts as a baseline.

Arrea as a CLI (lowest to highest priority)

  1. @default — Baseline values of the binary.
  2. Application env (if Arrea is used in a mix context).
  3. arrea config set KEY VALUE — Session config. Persists for the lifetime of the binary process. Uses the same mechanism as Config.set/2.
  4. CLI args — Highest priority. Applied to the current invocation only.

Example in config.exs

Acepta tanto keyword list como mapa:

# Keyword list (estilo estándar Elixir)
config :arrea, :engine,
  max_workers: 200,
  circuit_breaker_threshold: 10

# Mapa equivalente
config :arrea, :engine, %{max_workers: 200, circuit_breaker_threshold: 10}

Runtime usage

Arrea.Config.get(:max_workers)        # => 100 (default)
Arrea.Config.set(:max_workers, 50)    # persiste en la sesión actual
Arrea.Config.get(:max_workers)        # => 50

Summary

Functions

Returns all engine configuration values, merging the defaults with the Application env values.

Returns a configuration value from the engine.

Sets a configuration value in memory for the current session.

Functions

all()

@spec all() :: map()

Returns all engine configuration values, merging the defaults with the Application env values.

The result reflects the current effective configuration, including config.exs overrides and any changes applied with Config.set/2.

get(key, default \\ nil)

@spec get(atom(), any()) :: any()

Returns a configuration value from the engine.

Resolution (lowest to highest priority):

  1. @default of the module
  2. Application env (consumer's config.exs or Config.set/2 at runtime)

Function opts take priority over this value and should be checked first in the caller before falling back to Config.get/2.

Examples

iex> Arrea.Config.get(:max_workers)
100

iex> Arrea.Config.get(:nonexistent_key, :fallback)
:fallback

set(key, value)

@spec set(atom(), any()) :: :ok

Sets a configuration value in memory for the current session.

Los cambios persisten mientras viva el proceso de la VM. Para cambios permanentes, usar config.exs del proyecto consumidor.

En el contexto de CLI, equivale a arrea config set — los cambios se mantienen mientras el proceso del binario esté activo, pero no sobreviven a reinicios.

Examples

iex> Arrea.Config.set(:max_workers, 50)
:ok
iex> Arrea.Config.get(:max_workers)
50