/** * PgJobStore — PostgreSQL durability for indexing jobs (Phase 1, T9). * * Mirrors PgJobStore's semantics so the job store follows the same * one-backend rule as the rest of the data plane: getJobStore() selects this * variant when DATABASE_URL is postgres, else PgJobStore. * * Interface contract: JobStore is SYNCHRONOUS (the tracker calls * `store?.save(job)` and `store.get(id)` with no await, mirroring the sync * legacy local database API). PG is inherently async, so this store: * - Writes fire-and-forget (best-effort, logged on failure — matching the * PostgreSQL store's try/catch best-effort semantics). * - Reads are served from an in-memory mirror that is hydrated from PG on * first use (async) and kept in sync by every save. The mirror is the hot * read path within a process; PG is the durability + cross-process recovery * layer (crash recovery flips stale `running` → `failed` on init, and a new * process hydrates its mirror from the recovered rows). * * Uses raw SQL ($executeRaw / $queryRaw) via the shared prisma client — the * same pattern as MemoryRepositoryPg — to avoid the Prisma 7.7.0 + adapter-pg * isObjectEnumValue incompatibility. Reuses getPrismaClient() (no second pool). */ import type { IndexJob } from "./index-job-tracker.js"; import type { JobStore } from "./index-job-store-contract.js"; export declare class PgJobStore implements JobStore { private prisma; /** In-memory mirror: the sync read path. Hydrated from PG on first use. */ private mirror; private hydrated; private hydrating; /** Crash recovery guard: runs once per process on first use. */ private recovered; /** * Per-jobId serialized write chain. The tracker lifecycle calls save() many * times rapidly for one job (pending → running → progress → ... → completed). * Without ordering, these become concurrent in-flight upserts on the same * row with NO commit-order guarantee — an earlier write (e.g. `running`) can * commit AFTER the terminal write (`completed`) and leave the PG row stuck at * a non-terminal state. Chaining each persist onto the previous in-flight * write for that jobId guarantees persists commit in call order. Different * jobIds remain concurrent (independent rows). Settled entries are dropped so * the map does not grow. */ private inflight; private persistFailures; private getClient; /** * Stale-heartbeat cutoff (ms-epoch): running jobs whose * `COALESCE(heartbeat_at, started_at)` is older than this are considered * stale (crashed / orphaned) and may be flipped to `failed`. Sourced from * the same env knob the live reaper uses (MASSA_TH0TH_JOB_STALE_MS, default * 300000), so a live process with a fresh heartbeat is never touched. */ private staleHeartbeatCutoffMs; /** * Best-effort hydrate the mirror from PG + run crash recovery once. Resolves * (never rejects) — failures log a warn and leave the mirror empty; the * tracker's own in-memory Map remains the authoritative hot cache. */ private ensureHydrated; save(job: IndexJob): void; /** * Test-infrastructure helper (double-underscore): await the current in-flight * write(s) for a job (or all jobs if omitted). Lets tests assert the FINAL * on-disk PG state deterministically without polling. Not for production use. */ __drain(jobId?: string): Promise; flush(jobId?: string): Promise; private persist; get(jobId: string): IndexJob | null; listByProject(projectId: string): IndexJob[]; listAll(): IndexJob[]; listRunning(): IndexJob[]; markStaleRunningFailed(): number; delete(jobId: string): void; } //# sourceMappingURL=index-job-store-pg.d.ts.map