Queue operations
Pause admission and change declared queue limits across runtimes.
runlane.queues controls registered queues in the runtime's environment. Pass the same QueueDefinition used to construct the runtime. runlane.queueDefinitions is the readonly declaration array.
import { queue } from '@runlane/core'
import { runlane } from '../../runlane.js'
const billing = queue({ name: 'billing', concurrency: { total: 20, perKey: 2 } })
await runlane.queues.pause(billing)
await runlane.queues.resume(billing)
await runlane.queues.setLimit(billing, { total: 10 })
await runlane.queues.setLimit(billing, {
concurrencyKey: 'account.123',
perKey: 1,
})
const state = await runlane.queues.get(billing)
await runlane.queues.resetLimit(billing)Use your registered definition in place of this example's billing declaration.
| Method | Arguments | Result |
|---|---|---|
pause | queue | Promise<QueueState & DeliveryOutcome> |
resume | queue | Promise<QueueState & DeliveryOutcome> |
setLimit | queue, override | Promise<QueueState & DeliveryOutcome> |
resetLimit | queue, { concurrencyKey? }? | Promise<QueueState & DeliveryOutcome> |
get | queue, { concurrencyKey? }? | Promise<QueueState> |
QueueLimitOverrideInput and QueueControlOptionsInput accept plain strings for concurrency keys; validation returns branded keys internally.
A queue override accepts { total?, perKey?, expiresAt? } and requires at least one bound. A key override accepts { concurrencyKey, perKey, expiresAt? }. Bounds are positive safe integers. An override can change only a dimension present in the declaration. Adding a dimension while untracked attempts run would undercount capacity. Invalid bounds, scopes, dates, unknown queues, and mismatched declarations reject with configuration_invalid before writing.
setLimit replaces the entire override in the selected scope, including all bounds and expiry. It does not merge with the saved override. For example, setLimit(queue, { total: 4 }) removes any saved perKey bound and expiresAt; the new override has no expiry. A keyed setLimit replaces only that key's override, including its expiry. Repeat every bound and expiry you want to keep.
expiresAt is a Date strictly after storage time. Expired overrides stop applying during reads and admission, without a cleanup pass. A key override wins for that key's perKey; the queue override supplies other overridden bounds; declarations supply the rest. resetLimit(queue) clears only the queue override. The keyed form clears only that key. Pause remains until resume.
QueueState exposes name, paused, declared, optional active override and keyOverride, effective, optional expiresAt, and optional updatedAt. updatedAt is the latest saved control timestamp in the selected scope. Omitted bounds mean unbounded. Returned state is a projection; changing it does not edit policy. On bounded queues, get checks one bounded page of ownership records. If that complete, current view disagrees with the saved count, it rejects with invariant_violation. Partial views cannot prove count equality. See queue storage rules.
Every claim and reservation reads current controls in its transaction. Pause blocks new starts, including starts from existing dispatch reservations. Running attempts continue and renew normally. Lowering a bound leaves current owners alive and blocks new owners until the count falls below it. A reservation may transfer into execution only when the count is at or below the new bound.
Deliveries blocked by pause or a lowered capacity limit return the transport retry disposition before early acknowledgement. SQS receive visibility and retry delays prevent immediate repeated handling; FIFO's blocked head can block its message group. Lambda uses the same retry result for partial batch failure. Resume gives local workers an advisory wake hint; ordinary worker and maintenance intervals recover missed hints.
On an eager transport runtime, resume, setLimit, and resetLimit also try queue admission after the control is saved. They reserve ready runs within the current limits, in queue order, and return after the transport accepts those wakeups. One call inspects a bounded number of waiting runs; later releases and maintenance admit the rest. A failed attempt logs bounded_dispatch_failed and returns deliveryError with the saved control. pause admits nothing. Deferred transport runtimes leave admission to maintenance, and polling workers claim from storage. Inside a best-effort direct HTTP in_request delivery, queue controls save their changes and leave unrelated admission to maintenance. Outside delivery, accepting a wakeup includes running the task, so these calls return after the admitted runs finish. See HTTP delivery.
See limit concurrency for declared pools and CLI queue commands for terminal use.
Queue controls follow saved changes and delivery errors. resume, setLimit, and resetLimit report immediate admission failures in deliveryError; meta: { queue, runIds } identifies the queue and affected runs from admissions this control started. runIds is empty when the attempt stopped early but no named run still waits. pause uses the same result type but starts no admission. Keep maintenance running and do not repeat a saved control to recover delivery.