import { TaskContext } from "./context.js"; import type { TaskStore } from "./store/base.js"; import { type TaskDef } from "./task.js"; export type Handler = (ctx: TaskContext, payload: any) => unknown | Promise; /** Handler typed against a TaskDef: payload is P, the return is R. */ export type TypedHandler = (ctx: TaskContext, payload: P) => R | Promise; export interface WorkerOptions { concurrency?: number; leaseMs?: number; heartbeatIntervalMs?: number; pollIntervalMs?: number; claimBatch?: number; } export declare class Worker { private readonly store; private readonly queues; private readonly opts; private readonly handlers; private readonly workerId; private stopped; private stopResolvers; private ownsStore; constructor(store: TaskStore, queues: string[], opts?: WorkerOptions); static sqlite(path: string, opts?: WorkerOptions & { queues?: string[]; busyTimeoutMs?: number; }): Worker; /** Multi-host backend. `dsn` is a libpq connection string; requires the * optional `pg` package. */ static postgres(dsn: string, opts?: WorkerOptions & { queues?: string[]; max?: number; }): Worker; get id(): string; task(handler: Handler): this; task(name: string, handler: Handler): this; task(def: TaskDef, handler: TypedHandler): this; stop(): void; /** Close the underlying store connection. Call after run() returns. */ close(): Promise; private closeIfOwned; run(opts?: { concurrency?: number; }): Promise; /** Blocking-style entry point for a standalone worker process: run until * SIGINT/SIGTERM, then close the store. Use this at a script's top level; * use run() / background() when you manage the event loop yourself. */ serve(opts?: { concurrency?: number; }): Promise; /** Run the worker in the same process for the duration of fn (deployment mode A). */ background(fn: () => Promise, opts?: { concurrency?: number; }): Promise; private execute; private startHeartbeat; private safeFail; private sleepOrStop; private installSignals; }