# `AshWorkflow.Scheduler.Leader`
[🔗](https://github.com/team-alembic/ash_workflow/blob/v0.12.0/lib/ash_workflow/scheduler/leader.ex#L1)

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

* `AshWorkflow.Scheduler.Leader.Single` — always the leader. The default,
  correct on one node, and what every test wants.
* `AshWorkflow.Scheduler.Leader.Oban` — delegates to `Oban.Peer.leader?/2`,
  which is the same election `Oban.Stager` gates on. Correct across a
  cluster, and needs an Oban instance running.

## 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.

# `leader?`

```elixir
@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.

# `leader?`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
