Durable.Scheduler (Durable v0.1.0-rc)

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
  • Uses FOR UPDATE SKIP LOCKED for multi-node safety
  • Starts workflows via the normal queue system
  • Updates last_run_at and next_run_at after each execution

Multi-Node Safety

When running multiple Durable instances (e.g., multiple app nodes), only one node will execute each scheduled workflow. This is achieved using PostgreSQL's FOR UPDATE SKIP LOCKED clause, which allows each node to atomically claim schedules without conflicts.

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.