import { SmrtCollection, SmrtObject } from '@happyvertical/smrt-core'; /** * Liveness record for a single TaskRunner / ScheduleRunner incarnation, * stored in the `_smrt_workers` system table. * * @remarks * Job recovery asks "is this job's owning worker alive?" rather than "is this * job's heartbeat fresh?" (issue #1474). Each running worker keeps a row here * and renews `leaseExpiresAt` on a fixed cadence; a worker that dies stops * renewing and its lease expires, so its `running` jobs are recovered. * * `workerId` is unique per *incarnation* (a restarted runner gets a new key — * see `createWorkerKey`), which is what lets recovery distinguish a crashed * worker's orphaned jobs from an identically-configured restart. * * `leaseExpiresAt` is a `datetime` so it maps to a real timestamp column on * every engine (an integer epoch-ms column overflows `int4`/`INT32` on * Postgres and DuckDB). Stage 1 writes/compares it against the host clock — * the same approach the previous heartbeat recovery used; Stage 2 will move to * database-side time once an off-loop writer exists. */ export declare class SmrtWorker extends SmrtObject { /** Per-incarnation-unique worker key (also stored on owned jobs' workerId). */ workerId: string; /** OS process id of the owning runner (diagnostic). */ pid: number | null; /** Hostname of the owning runner (diagnostic). */ hostname: string | null; /** When this incarnation started. */ startedAt: Date | null; /** Last lease renewal time (diagnostic; liveness uses leaseExpiresAt). */ heartbeatAt: Date | null; /** Lease expiry — the worker is alive while this is in the future. */ leaseExpiresAt: Date | null; /** Lifecycle status (`running` while the runner is processing). */ status: string; } export interface RegisterWorkerInput { workerKey: string; pid?: number | null; hostname?: string | null; leaseTtlMs: number; } /** * Collection for managing `_smrt_workers` liveness rows. */ export declare class SmrtWorkerCollection extends SmrtCollection { static readonly _itemClass: typeof SmrtWorker; /** * Fail fast if the `_smrt_workers` table has not been migrated. * * The framework never creates application/system tables at runtime; the * table is created by `smrt db:migrate` (or `getTestDatabase`). A consumer * that upgrades smrt-jobs without migrating must get a clear, actionable * error at `start()` rather than a confusing recovery failure later. */ assertReady(): Promise; /** Whether the `_smrt_workers` table exists (recovery skips lease checks if not). */ tableReady(): Promise; /** Register a worker incarnation with its lease seeded to `now + ttl`. */ registerWorker(input: RegisterWorkerInput): Promise; /** Renew a worker's lease to `now + ttl`. */ renewLease(workerKey: string, leaseTtlMs: number): Promise; /** Remove a worker incarnation (graceful shutdown). */ expireWorker(workerKey: string): Promise; /** Worker keys whose database lease is still fresh (alive cross-process). */ freshLeaseWorkerKeys(): Promise>; /** Delete worker rows whose lease expired more than `graceMs` ago. */ pruneExpired(graceMs: number): Promise; } export default SmrtWorker; //# sourceMappingURL=smrt-worker.d.ts.map