import type { Kysely } from 'kysely'; import type { FrameworkContext } from '@rangka/shared'; import type { JobRegistry } from './registry.js'; import type { JobWorkerConfig } from './types.js'; /** * Polls the database for pending jobs, claims them, and executes their handlers. * Supports concurrency limits, retry with backoff, and graceful shutdown. */ export declare class JobWorker { private running; private pollTimer; private activeJobIds; private readonly pollInterval; private readonly db; private readonly registry; private readonly ctx; private shutdownResolve; constructor(db: Kysely, registry: JobRegistry, ctx: FrameworkContext, config?: JobWorkerConfig); /** Begin polling for jobs. */ start(): void; /** Stop polling and wait for in-flight jobs to finish. */ stop(): Promise; isRunning(): boolean; getInFlightCount(): number; /** Single poll iteration: claim a batch of jobs, execute them, then schedule the next poll. */ private poll; /** Claim available jobs from the database and run them concurrently. */ private claimAndExecute; /** * Fetch pending jobs that this worker can handle, respecting concurrency limits. * Uses SELECT FOR UPDATE SKIP LOCKED to allow multiple workers without conflicts. */ private claimJobs; /** Query the database for jobs that are ready to run. */ private fetchPendingJobs; /** Filter jobs by concurrency limits and mark them as active. */ private claimWithConcurrencyCheck; /** Returns true if the job type already has too many active instances. */ private exceedsConcurrencyLimit; private getActiveCount; /** Run a single job's handler, then mark it completed or handle failure. */ private executeJob; /** If the worker is stopping and no jobs remain in flight, signal completion. */ private resolveShutdownIfDrained; private markCompleted; /** Either schedule a retry (with backoff) or move the job to the dead-letter table. */ private handleFailure; /** Reset the job to 'created' with a delayed start_after timestamp. */ private scheduleRetry; /** Permanently fail the job: archive it to dead letters and mark it failed. */ private moveToDeadLetter; /** Calculate how long to wait before the next retry attempt. */ private computeBackoffDelay; } //# sourceMappingURL=worker.d.ts.map