Skip to content

All-or-none claim

The queue as a marketHTTPSDKCLIMCPclaimByFacetsallOrNone

Claim exactly N rows or none. A dispatcher that needs four free stations either locks four or locks nothing and tries again.

The situation

A dispatcher has claimed four orders and needs four ready stations to run them. Locking three would strand the fourth order and hold three stations that cannot be used as a set.

The recipe

services/dispatcher.ts
const { data } = await lt.escalations.claimByFacets({
query: { role: 'stations', facets: { state: 'ready', material: 'steel' } },
limit: 4,
durationMinutes: 30,
allOrNone: true,
});
if (!data?.claimed.length) {
// fewer than four were free: nothing was locked
}
The same from a terminal
ltc esc claim-by-facets --role stations --facets '{"state":"ready"}' --limit 4 --all-or-none

Without allOrNone, the call locks up to limit available rows in rank order. With it, the transaction commits only when the full limit is acquired.

The guarantee

On a shortfall the transaction rolls back and returns an empty set, so no row is left half-held. Rows are taken with FOR UPDATE SKIP LOCKED, so a competing dispatcher skips rows already locked rather than waiting on them. See Faceted routing.