AshWorkflow.Scheduler.Leader behaviour (AshWorkflow v0.6.0)

Copy Markdown View Source

Answers whether this node is the one that should arm timers.

AshWorkflow.Scheduler.Precise holds its deadlines in memory. Two nodes holding the same timer fire the same deadline twice, so exactly one node may arm them. This behaviour is how Precise asks which node that is, and it is one callback so that a deployment can answer the question with whatever it already runs.

The implementations

Choosing one

workflow do
  scheduler {AshWorkflow.Scheduler.Precise, leader: AshWorkflow.Scheduler.Leader.Oban}
end

Or with options for the implementation:

scheduler {AshWorkflow.Scheduler.Precise, leader: {AshWorkflow.Scheduler.Leader.Oban, name: MyApp.Oban}}

Single is the default because a workflow running on one node should not have to configure an election to get a timer. Precise logs a warning at boot when it is running on Single and more than one node is connected, since that is the configuration where deadlines fire twice.

Summary

Callbacks

Whether this node should arm timers.

Functions

Ask the configured leader implementation whether this node should arm timers.

Callbacks

leader?(opts)

@callback leader?(opts :: keyword()) :: boolean()

Whether this node should arm timers.

Called before arming a deadline and again before firing one. An implementation that talks to the network must not raise: return false when it cannot tell, so that a poll picks the work up rather than two nodes racing.

Functions

leader?(arg)

@spec leader?({module(), keyword()}) :: boolean()

Ask the configured leader implementation whether this node should arm timers.

A raising implementation answers false. Losing a deadline to the polled fallback is recoverable; crashing the process that holds every other timer is not.