GenDurable.Supervisor (gen_durable v0.2.12)

Copy Markdown View Source

Top-level engine supervisor. Started by the host (Oban-style) as {GenDurable, opts} in their own supervision tree.

Options

  • :name — the instance identity (an atom, default GenDurable). Everything an instance owns — its supervisor registration, task supervisor, config entry, FSM registry — is keyed by it, so several engines (e.g. different repos, or disjoint queue sets) coexist; address API calls with name:. Starting two instances with the same name fails with :already_started.
  • :repo — the host's Ecto.Repo (required).
  • :fsms — FSM modules to register explicitly (default []). Only needed for a custom :name or to keep an old :version running; otherwise a machine is resolved from the fsm column (its module name). See GenDurable.Registry.
  • :queues — keyword list of queue_name => concurrency (default [default: 10]). [] runs no schedulers — this node only inserts/signals (see the topologies section of the operations guide).
  • :lease_ttl, :heartbeat_interval, :poll_interval — timings in ms (balanced defaults: 60_000 / 20_000 / 1_000).
  • :reaper — the lease-reclamation sweeper: [interval: 30_000] (ms), or false to not run one on this node.
  • :gc — the retention/maintenance sweeper: [interval: 60_000, retention: 86_400_000, batch: 10_000] (ms between sweeps; ms a done/failed row is kept after it terminates; max rows deleted per sweep), or false to not run one on this node.
  • :poke — how an insert announces new work to schedulers (see GenDurable.Poke): :local (default) — the caller's node only; :cluster — every node, over Erlang distribution; {:redis, url_or_opts} — Redis Pub/Sub, for clusters without distribution (requires the optional :redix dependency; the value is passed to Redix.start_link/1). Best-effort in every mode — the poll interval is the discovery floor.
  • :await — tuning for GenDurable.await/3: [tick: 25] (ms between the batched watcher's probes — the latency granularity for results committed on OTHER nodes; same-node results are pushed instantly). Idle-free, so there is no false.

reaper: false / gc: false are per-node knobs for topology (a web-only or worker-only node), not switches you may flip everywhere: the cluster needs at least one node running each, or expired leases are never reclaimed and terminal rows / stale limiter counters accumulate forever. Running them on several nodes is safe (sweeps claim via ordered SKIP LOCKED), just redundant.

  • :prefetch — extra rows each queue claims and buffers beyond its running slots (default 0 ⇒ no over-fetch). See GenDurable.Scheduler.
  • :min_demand — batch gate for the picker (default 1).
  • :max_poll_interval — idle-backoff ceiling in ms (default 5_000).
  • :drain_timeout — on shutdown, how long (ms) each queue waits for its in-flight steps to finish before giving up to the reaper (default 5_000). Buffered (un-started) rows are released immediately regardless.
  • :rate_limits — named token-bucket rate limits (default []), e.g. [stripe: [allowed: 100, period: {1, :minute}], emails: [allowed: 5, period: 60, burst: 10, shards: 4]]. allowed/period set the sustained rate; burst (default allowed) the capacity. shards (default 1) splits rate/burst across bucket rows so concurrent (cross-node) pickers grab disjoint shards instead of serializing — size it to the number of nodes that contend the hottest key. A step opts into a limit by returning rate_limit: :stripe (or {:stripe, key}).
  • :concurrency_limits — named concurrency caps for concurrency_key (default []), e.g. [stripe: [limit: 1000, shards: 10]]: at most limit concurrent executions per key whose name matches (concurrency_key: {:stripe, tenant} ⇒ key "stripe:tenant", name "stripe"). An unconfigured key keeps the default limit of 1 (mutual exclusion). shards (default 1, clamped to limit) splits the cap across bucket rows so cross-node pickers take disjoint shards and completions credit back per shard — size shards ≥ contending nodes. Careful: a config name captures every key with that prefix — configuring a name that collides with identity-style keys (e.g. order: used for mutual exclusion) silently raises their limit and breaks the exclusion.

:prefetch, :min_demand, and :max_poll_interval are the feeder aggressiveness knobs and apply to every queue; see GenDurable.Scheduler for the trade-offs (DB chatter vs. latency vs. cross-node fairness).

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)