//#region src/core/queues/index.d.ts /** * A deferred post-write side-effect drained by a Worker's `queue()` consumer * (#77)—keeps the write path to just the DB mutation while derived work runs * async. An extensible discriminated union; match on `kind`. `reindex` (the * first member) re-syncs one collection row's FTS entry: it's enqueued by * `versionsRoute`'s `deferReindex` and drained with `reindexDoc` * (louise-toolkit/content), which upserts the row's index entry or removes it if * the row is gone. */ type SideEffectJob = { kind: "reindex"; /** Collection slug—the consumer maps it to a table + config. */ collection: string; /** The changed row's id (the FTS rowid). */ id: number; }; /** Enqueues `message` onto `queue`. Throws LouiseQueueError on failure. */ declare function enqueue(queue: Queue, message: T): Promise; /** * Called once per message in a batch. Throwing marks that message for * retry; returning normally acks it. `attempts` is the 1-indexed delivery * count CF Queues reports on the message itself. */ type QueueMessageHandler = (message: T, context: { attempts: number; }) => void | Promise; /** Options for {@link processBatch}. */ interface ProcessBatchOptions { /** * Seconds to wait before Cloudflare redelivers a failed message, given its * 1-indexed delivery attempt. Defaults to {@link defaultRetryDelay}: 30 * seconds, doubling each attempt, capped at 5 minutes. Return 0 to redeliver * with no delay. */ retryDelay?: (attempts: number) => number; /** * The queue's `max_retries`, as set in `wrangler.jsonc`. Defaults to * {@link DEFAULT_MAX_RETRIES}, Cloudflare's own default. A message that * fails on delivery `maxRetries + 1`, its last, is reported as a `queue` * incident (ADR 0022 § 7); an earlier failure is only logged, because a * retry may still clear it. */ maxRetries?: number; } /** Cloudflare Queues' default `max_retries`: 3 retries, so 4 deliveries. */ declare const DEFAULT_MAX_RETRIES = 3; /** * The default backoff for a failed message: 30 seconds on the first * delivery, then a minute, then two, doubling up to a 5-minute cap. */ declare function defaultRetryDelay(attempts: number): number; /** * Drains a `MessageBatch`, running `handler` once per message. Each * message is acked or retried independently—one failing message * doesn't block the rest of the batch from acking. Never throws itself; * a handler's own errors are caught and turned into a `retry()` so a * Worker's `queue()` export can call this directly as its entire body. * * Before each retry, `processBatch` logs the failure with `console.error`: * the queue name, the message id, and the delivery attempt, with the error * itself as the second argument. Without that line, a failure leaves no trace * in Workers Logs—once the queue's `max_retries` is spent, Cloudflare moves * the message to the dead-letter queue, or drops it if there's none, and logs * nothing. * * On a message's last delivery, the failure is also reported as a `queue` * incident, named for the error and pathed with the queue's name. It reaches * the sinks of `composeWorker`'s `onIncident` when the Worker's `queue` * handler finishes; without `onIncident`, the log line is the only trace. * * A retry waits before redelivery, by `options.retryDelay` or * {@link defaultRetryDelay}. A failure from an upstream rate limit or outage * rarely clears in the same second, so an immediate redelivery only spends a * try. Retries inside a handler multiply with queue redeliveries: a handler * that makes up to 4 calls per delivery, on a queue with `max_retries: 5`, * makes up to 24 calls for one message. Keep the in-handler retries few and * let the queue's backoff do the waiting. */ declare function processBatch(batch: MessageBatch, handler: QueueMessageHandler, options?: ProcessBatchOptions): Promise; //#endregion export { DEFAULT_MAX_RETRIES, ProcessBatchOptions, QueueMessageHandler, SideEffectJob, defaultRetryDelay, enqueue, processBatch };