Durable.Scheduler (Durable v2.0.2)

View Source

GenServer that polls for due scheduled workflows and triggers them.

This module runs as part of the Durable supervision tree and:

  • Polls every 60 seconds for due schedules
  • Claims each fire with one conditional update, for multi-node safety
  • Starts workflows via the normal queue system
  • Updates last_run_at and next_run_at as it claims each fire

Multi-Node Safety

When running multiple Durable instances (e.g., multiple app nodes), only one node starts each fire of a schedule. Each node that sees a schedule due tries to move its next_run_at on from the value it read, and only the one whose update matched a row starts the run. The update and the start commit together, so a node that dies between them leaves the fire to the next.

Configuration

The scheduler is automatically started when Durable starts. No additional configuration is required.

Summary

Functions

Manually triggers a check for due schedules.

Returns a specification to start this module under a supervisor.

Returns the process name for a given Durable instance.

Starts the scheduler process.

Returns the current state of the scheduler for debugging.

Functions

check_schedules(durable_name \\ Durable)

@spec check_schedules(atom()) :: :ok

Manually triggers a check for due schedules.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

scheduler_name(durable_name)

@spec scheduler_name(atom()) :: atom()

Returns the process name for a given Durable instance.

start_link(opts)

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

Starts the scheduler process.

Options

  • :config - The Durable configuration (required)
  • :interval - Poll interval in milliseconds (default: 60_000)
  • :scheduled_modules - List of modules to register on startup

status(durable_name \\ Durable)

@spec status(atom()) :: map()

Returns the current state of the scheduler for debugging.