Cyclium.WorkClaims.EctoClaims (Cyclium v0.1.7)

Copy Markdown View Source

Default Ecto-based work claims implementation. Works with any Ecto adapter.

Acquisition is race-free without row locks: every takeover is a single conditional UPDATE ... WHERE <the state we read still holds> and we treat a zero-row result as "someone else won" (:busy). A brand-new claim is an INSERT whose unique dedupe_key index turns a concurrent first-acquire into :busy rather than a duplicate. This preserves at-most-once across nodes on READ COMMITTED (the Postgres/SQL Server default) — two nodes can never both believe they hold the same lease.

A SQL Server adapter using UPDLOCK/READPAST hints is an optional throughput optimization, not a correctness requirement.

The state column is an Ecto.Enum — all reads and writes use atoms (:claimed, :done, :failed, :expired).