import { RetentionPolicy, RetentionSweepResult } from '@happyvertical/smrt-core'; import { DatabaseInterface } from '@happyvertical/sql'; /** Retention task name for terminal rows in `_smrt_jobs`. */ export declare const JOBS_RETENTION_TASK = "jobs-records"; /** Retention task name for `_smrt_job_events`. */ export declare const JOB_EVENTS_RETENTION_TASK = "jobs-events"; /** Windows applied by the job retention tasks. */ export interface JobRetentionOptions { /** Delete completed jobs finished more than this many days ago (default 7). */ completedOlderThanDays?: number; /** Delete cancelled jobs finished more than this many days ago (default 7). */ cancelledOlderThanDays?: number; /** Delete failed jobs finished more than this many days ago (default 30). */ failedOlderThanDays?: number; /** Delete job events recorded more than this many days ago (default 30). */ eventsOlderThanDays?: number; /** Maximum job rows removed per sweep (default 10 000). */ batchSize?: number; } /** * Documented job retention defaults. * * Completed and cancelled work is the bulk of the table and is uninteresting * within a week; failures are kept a month because that is how long anyone * looks at them. Events outlive the jobs they describe by design — a job row * deleted at 7 days can still have its log read for another three weeks. */ export declare const DEFAULT_JOB_RETENTION: Required; /** * Register the job and job-event retention tasks with the framework sweep. * * Idempotent: re-registering replaces the previous tasks, so repeated calls * (multiple runners in one process, module re-evaluation) do not duplicate * work. */ export declare function registerJobRetentionTasks(options?: JobRetentionOptions): void; /** Remove the job retention tasks from the framework sweep. */ export declare function unregisterJobRetentionTasks(): void; /** Configuration for {@link startRetentionSweeper}. */ export interface RetentionSweeperOptions { /** How often to sweep, in milliseconds (default 6 hours). */ intervalMs?: number; /** Policy handed to `runRetentionSweep` on each tick. */ policy?: RetentionPolicy; /** Windows for the job retention tasks this sweeper registers. */ jobs?: JobRetentionOptions; } /** Handle returned by {@link startRetentionSweeper}. */ export interface RetentionSweeper { /** Stop the periodic sweep timer. Does not unregister the job tasks. */ stop(): void; /** Run one sweep immediately (used by tests and by manual triggers). */ sweepNow(): Promise; } /** Default sweep cadence: four times a day is ample for day-scale windows. */ export declare const DEFAULT_RETENTION_SWEEP_INTERVAL_MS: number; /** * Start a periodic retention sweep on an interval. * * The first sweep runs one full interval after start, never at start: a worker * process restarting in a crash loop must not turn into a delete loop, and a * short-lived process (a test, a one-shot worker) should exit without having * deleted anything it was not asked to. * * The timer is `unref`'d where the runtime supports it, so a pending sweep * never keeps a process alive. * * **`stop()` never unregisters the job tasks.** The package entry point * (`index.ts`) registers them unconditionally on import, so "this process * loaded `@happyvertical/smrt-jobs`" is what contributes them — not "a * sweeper happens to be running". Making `stop()` unregister would silently * break that contract the moment a `TaskRunner` restarts (or a second, * independent caller in the same process runs `runRetentionSweep()` after * the first sweeper stops): the tasks would vanish from the sweep even * though the package is still loaded. `options.jobs` still lets a caller * override the default windows — each call to this function re-registers * with whatever config it was given, the same idempotent replace * {@link registerJobRetentionTasks} already documents. Callers that want a * genuinely clean registry (tests, teardown) call * {@link unregisterJobRetentionTasks} themselves. * * @param db - Database holding the system tables. * @param options - Cadence and policy overrides. * @returns A handle that stops the periodic timer. */ export declare function startRetentionSweeper(db: DatabaseInterface, options?: RetentionSweeperOptions): RetentionSweeper; //# sourceMappingURL=retention.d.ts.map