Durable.Config (Durable v0.1.0-rc)

View Source

Configuration management for Durable.

Durable configuration is validated at startup and stored in persistent_term for fast runtime access.

Options

  • :repo - The Ecto repo module to use for persistence (required)
  • :name - Instance name for multiple Durable instances (default: Durable)
  • :prefix - PostgreSQL schema name for table isolation (default: "durable")
  • :queues - Queue configuration map (default: %{default: [concurrency: 10, poll_interval: 1000]})
  • :queue_enabled - Enable/disable queue processing (default: true)
  • :stale_lock_timeout - Seconds before a lock is considered stale (default: 300)
  • :heartbeat_interval - Milliseconds between worker heartbeats (default: 30_000)
  • :log_level - Log level for Ecto queries, or false to disable (default: false)

Examples

# Single instance (most common)
{Durable, repo: MyApp.Repo}

# With custom queues
{Durable,
 repo: MyApp.Repo,
 queues: %{
   default: [concurrency: 10],
   high_priority: [concurrency: 20, poll_interval: 500]
 }}

# Multiple instances with different prefixes
{Durable, repo: MyApp.Repo, name: :workflows_a, prefix: "durable_a"}
{Durable, repo: MyApp.Repo, name: :workflows_b, prefix: "durable_b"}

Summary

Functions

Removes the configuration for a Durable instance.

Retrieves the configuration for a Durable instance.

Retrieves the configuration, returning nil if not set.

Gets the heartbeat interval for a Durable instance.

Creates a new validated configuration from options.

Creates a new validated configuration, raising on error.

Gets the database prefix for a Durable instance.

Stores the configuration for a Durable instance.

Checks if queue processing is enabled for a Durable instance.

Gets the queues configuration for a Durable instance.

Gets the repo module for a Durable instance.

Returns the NimbleOptions schema for documentation.

Gets the stale lock timeout for a Durable instance.

Returns the Task.Supervisor name for a Durable instance.

Types

t()

@type t() :: %Durable.Config{
  heartbeat_interval: pos_integer(),
  log_level: false | :debug | :info | :warning | :error,
  name: atom(),
  owns_pubsub?: boolean(),
  prefix: String.t(),
  pubsub: atom() | nil,
  queue_enabled: boolean(),
  queues: map(),
  repo: module(),
  scheduled_modules: [module()],
  scheduler_interval: pos_integer(),
  sleep_waker_batch_size: pos_integer(),
  sleep_waker_interval: pos_integer(),
  stale_lock_timeout: pos_integer()
}

Functions

delete(name)

@spec delete(atom()) :: :ok

Removes the configuration for a Durable instance.

get(name \\ Durable)

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

Retrieves the configuration for a Durable instance.

Raises if the configuration hasn't been set.

get_safe(name \\ Durable)

@spec get_safe(atom()) :: t() | nil

Retrieves the configuration, returning nil if not set.

heartbeat_interval(name \\ Durable)

@spec heartbeat_interval(atom()) :: pos_integer()

Gets the heartbeat interval for a Durable instance.

new(opts)

@spec new(keyword()) :: {:ok, t()} | {:error, NimbleOptions.ValidationError.t()}

Creates a new validated configuration from options.

Returns {:ok, config} if valid, {:error, reason} otherwise.

Respects the :durable app env key :disable_queue_processing. When set to true, it forces queue_enabled: false regardless of the user's opts. Mix tasks set this before booting the host app so they don't accidentally claim jobs they can't finish.

new!(opts)

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

Creates a new validated configuration, raising on error.

prefix(name \\ Durable)

@spec prefix(atom()) :: String.t()

Gets the database prefix for a Durable instance.

put(name, config)

@spec put(atom(), t()) :: :ok

Stores the configuration for a Durable instance.

Configuration is stored in persistent_term for fast lookups.

queue_enabled?(name \\ Durable)

@spec queue_enabled?(atom()) :: boolean()

Checks if queue processing is enabled for a Durable instance.

queues(name \\ Durable)

@spec queues(atom()) :: map()

Gets the queues configuration for a Durable instance.

repo(name \\ Durable)

@spec repo(atom()) :: module()

Gets the repo module for a Durable instance.

schema()

@spec schema() :: keyword()

Returns the NimbleOptions schema for documentation.

stale_lock_timeout(name \\ Durable)

@spec stale_lock_timeout(atom()) :: pos_integer()

Gets the stale lock timeout for a Durable instance.

task_supervisor(name \\ Durable)

@spec task_supervisor(atom()) :: atom()

Returns the Task.Supervisor name for a Durable instance.

This supervisor is used for parallel step execution.