import type { DB } from '../../data/db/index.js'; import type { DefinedTable } from '../../data/domain/types.js'; import type { ListenClient, WaitOptions, WaitResult } from './listener.js'; import type { ScheduleSpec, ScheduleInfo, SchedulerOptions } from './scheduler.js'; import type { ExclusionConfig } from './exclusion.js'; export interface BackoffConfig { readonly type: 'exponential' | 'fixed'; readonly delayMs: number; readonly maxDelayMs?: number; } /** Queue configuration — table name, stale timeout, max attempts, backoff strategy, cross-job exclusion. */ export interface QueueConfig { readonly table?: string; readonly staleTimeoutMs?: number; readonly notifyChannel?: string; readonly claimFilter?: (candidateAlias: string) => string; readonly maxAttempts?: number; readonly backoff?: BackoffConfig; /** Cross-job exclusion gate — overlap/blocks-all/tenant columns checked against claimed/running jobs at claim time. */ readonly exclusion?: ExclusionConfig; } /** Exclusion values for one job — mapped onto the configured exclusion columns. */ export interface EnqueueExclusion { /** Conflict set for the configured arrayColumn; null/omitted = non-participating. */ readonly array?: readonly string[] | null; /** TRUE makes this job exclusive against every participating job in its scope. */ readonly blocksAll?: boolean; /** Tenant value for the configured tenantColumn — required when one is configured. */ readonly tenant?: string; } /** Options for enqueuing a job — type, payload, priority, max attempts. */ export interface EnqueueOptions { readonly type: string; readonly priority?: number; readonly payload: unknown; readonly maxAttempts?: number; readonly exclusion?: EnqueueExclusion; } /** The exclusion values a claimed job carries — present when the queue configures exclusion. */ export interface ClaimedExclusion { readonly array: readonly string[] | null; readonly blocksAll: boolean; readonly tenant: string | null; } /** A job claimed by a worker — includes ID, type, payload, and created LSN. */ export interface ClaimedJob { readonly id: string; readonly type: string; readonly priority: number; readonly payload: unknown; readonly createdLsn: string; /** Minted by this claim's own UPDATE; nulled when the claim ends. Compare it exactly to fence writes made under this claim. */ readonly claimToken: string; readonly exclusion?: ClaimedExclusion; } export interface JobResult { readonly status: 'completed' | 'failed' | 'cancelled' | 'timeout' | 'dead_letter'; readonly output?: unknown; readonly error?: unknown; } /** Job queue instance with claim/complete/fail lifecycle, LISTEN/NOTIFY, and cron scheduling. */ export interface Queue { /** The queue table as a pipe.define() definition — `pipework generate` emits its DDL. */ readonly definition: DefinedTable; enqueue(db: DB, opts: EnqueueOptions): Promise; /** Claims the next eligible job, retrying transient conflicts until clean. The signal ends the retry loop on shutdown — claim resolves null promptly. */ claim(db: DB, workerId: string, signal?: AbortSignal): Promise; heartbeat(db: DB, jobId: string): Promise; complete(db: DB, jobId: string, output?: unknown): Promise; fail(db: DB, jobId: string, error: unknown): Promise; cancel(db: DB, jobId: string): Promise; reap(db: DB): Promise; requeueDeadLetter(db: DB, jobId: string): Promise; startListener(client: ListenClient): Promise; stopListener(): Promise; waitFor(db: DB, jobId: string, opts: WaitOptions): Promise; enqueueAndWait(db: DB, opts: EnqueueOptions, waitOpts: WaitOptions): Promise; schedule(db: DB, spec: ScheduleSpec): Promise; unschedule(db: DB, name: string): Promise; listSchedules(db: DB): Promise; startScheduler(db: DB, opts?: SchedulerOptions): void; stopScheduler(): void; } export declare function createQueue(config?: QueueConfig): Queue; //# sourceMappingURL=queue.d.ts.map