Skip to content

Availability is a query

The queue as a marketHTTPSDKCLIMCPDashboardavailableassigned_untilclaimByFacets

A row is held only while its claim window is live. Availability is computed at read time, so no job has to flip a flag back.

The situation

A dispatcher claims machines for thirty minutes. If it crashes, those machines must be free again when the window ends, with nothing running to free them.

The recipe

services/dispatcher.ts
const free = await lt.escalations.searchByFacets({
role: 'cells',
status: 'pending',
available: true,
facets: { state: 'ready' },
});
const held = await lt.escalations.searchByFacets({
role: 'cells',
status: 'pending',
available: false,
});
The lt_escalations view column
available = assigned_to IS NULL OR assigned_until IS NULL OR assigned_until <= NOW()

available: true keeps unclaimed and lapsed rows. available: false keeps rows held right now. Claims set assigned_to and assigned_until; default 30 minutes.

The guarantee

Held means assigned_to is set and assigned_until is in the future, evaluated in the query itself. A crashed holder’s rows return to the pool when their windows pass, with status still pending. Claims take rows with FOR UPDATE SKIP LOCKED, so many consumers can pull from one pool without contention. See Faceted routing.