Karta. Claim
(Karta v1.0.0)
Takes rows for one run of a job with one conditional update, so that two runs of the same work never take the same row.
A row is taken while its claim field is empty or due; the same statement
moves the field forward by the claim period. A second run at the same
time takes nothing and ends; a run that crashes leaves its rows to be
taken again when the claim runs out. The caller's query says which rows
it may take (a message and domain, a status); take/5 adds the due
condition and the limit, so the guarantee does not depend on every
caller writing the condition the same way.
The claim field is :next_attempt_at for a delivery (a recipient of an
outgoing message, a delivery to an endpoint) and :sending_until for a
webhook delivery. A claim period longer than the job's own time limit
keeps a second run away for as long as the first can still be sending;
when the job is killed, the claim is what bounds the wait before a
retry.
Summary
Functions
Takes up to limit rows of queryable whose field is empty or not
after now, sets that field to now + seconds, and returns the ids it
took (in no particular order). :limit (optional) bounds how many.
Functions
@spec take(Ecto.Queryable.t(), atom(), DateTime.t(), pos_integer(), keyword()) :: [ term() ]
Takes up to limit rows of queryable whose field is empty or not
after now, sets that field to now + seconds, and returns the ids it
took (in no particular order). :limit (optional) bounds how many.