import type { Clock } from '../ports/clock.js'; import type { EventBacklog } from '../ports/eventBacklog.js'; import type { Logger } from '../ports/logger.js'; /** The queue is looked at this often at most, not before every row (§ 8.5). */ export declare const BACKLOG_SAMPLE_MS = 1000; export interface BacklogLimits { /** The worker pauses when more events than this are waiting. */ high: number; /** It goes on when fewer than this are. Below `high`, so that it does not flap. */ low: number; /** It gives up when a pause has lasted this long. */ maxWaitMs: number; } /** * What the gate says about the next row: write it (`go`), the run has to stop * (`stopped`: a cancel, a SIGTERM, or a job that is no longer ours; the reason is * on the run), or the queue did not drain in time (`gave_up`, J5). */ export type GateResult = 'go' | 'stopped' | 'gave_up'; export interface BacklogGateDeps { backlog: EventBacklog; clock: Pick; logger: Logger; limits: BacklogLimits; /** Aborted when the run has to stop; a pause ends at its next look. */ signal: AbortSignal; /** For the log lines. */ jobId: number; /** Tells the job that the worker waits or not; false when the job is no longer ours. */ setWaiting(waiting: boolean): Promise; } /** * Backpressure on the event queue (§ 8.5). The runner asks `pass()` before it * writes a row. Most of the time the answer is `go` at once and without a query: * the queue is looked at at most once a second. When more than `high` events are * waiting the gate marks the job as waiting and holds the run, looking every * second, until fewer than `low` are (a gap between the two, so that the run * does not stop and start on every other row). A pause that lasts `maxWaitMs` * ends the wait with `gave_up`. * * A look that fails is not a reason to stop an import: if the run is going, it * goes on; if it is waiting, it goes on waiting (and the time counts). */ export declare class BacklogGate { private readonly deps; private sampledAt; constructor(deps: BacklogGateDeps); pass(): Promise; /** * After the last unit (IMP-08): waits until fewer than `low` events are waiting, * for at most `maxWaitMs`, so that the events of the import are handled before * the page addresses are checked. `drained` also when the queue cannot be * measured: the repair does not touch a record whose event is still to be * handled, so it can go on without the answer. */ settle(): Promise<'drained' | 'stopped' | 'gave_up'>; private waitUntilBelowLow; /** The depth of the queue, or null when it could not be read. */ private sample; }