mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-07 07:55:47 +01:00
Reviewed and verified at 6a4c193906.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
import { registerActiveRunSilenceWork } from "./adapters/deadline-work.js";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { createPostgresWatchdogAdapter } from "./adapters/postgres.js";
|
|
import { createProcessAdapter } from "./adapters/process.js";
|
|
import {
|
|
createBuildRunOutputSilence,
|
|
createFoldSourceResolvedRun,
|
|
createRecordWatchdogDecision,
|
|
createScanSilentActiveRuns,
|
|
} from "./application/use-cases.js";
|
|
|
|
export type ActiveRunWatchdogConfig = {
|
|
suspicionThresholdMs: number;
|
|
criticalThresholdMs: number;
|
|
continueRearmMs: number;
|
|
};
|
|
|
|
/**
|
|
* Composes the active-run output watchdog module: the Postgres adapter,
|
|
* the process adapter, and the four use cases. The recovery service holds
|
|
* the only caller.
|
|
*/
|
|
export function createActiveRunWatchdog(db: Db, config: ActiveRunWatchdogConfig) {
|
|
const postgresAdapter = createPostgresWatchdogAdapter(db);
|
|
const processController = createProcessAdapter();
|
|
|
|
const foldSourceResolvedRun = createFoldSourceResolvedRun({
|
|
reader: postgresAdapter,
|
|
writer: postgresAdapter,
|
|
processController,
|
|
});
|
|
|
|
const scanSilentActiveRuns = createScanSilentActiveRuns({ reader: postgresAdapter, foldSourceResolvedRun,
|
|
suspicionThresholdMs: config.suspicionThresholdMs });
|
|
|
|
return {
|
|
registerSilenceWork: (coordinator: Parameters<typeof registerActiveRunSilenceWork>[1], canRun: () => boolean,
|
|
scan = scanSilentActiveRuns, enabled = async () => true) => registerActiveRunSilenceWork(db, coordinator, { reader: postgresAdapter,
|
|
scan, enabled, suspicionThresholdMs: config.suspicionThresholdMs }, canRun),
|
|
buildRunOutputSilence: createBuildRunOutputSilence({
|
|
reader: postgresAdapter,
|
|
suspicionThresholdMs: config.suspicionThresholdMs,
|
|
criticalThresholdMs: config.criticalThresholdMs,
|
|
}),
|
|
scanSilentActiveRuns,
|
|
recordWatchdogDecision: createRecordWatchdogDecision({
|
|
reader: postgresAdapter,
|
|
writer: postgresAdapter,
|
|
continueRearmMs: config.continueRearmMs,
|
|
}),
|
|
};
|
|
}
|
|
|
|
export type ActiveRunWatchdog = ReturnType<typeof createActiveRunWatchdog>;
|
|
|
|
export type {
|
|
RunOutputSilenceSummary,
|
|
ScanSilentActiveRunsResult,
|
|
WatchdogDecisionActor,
|
|
WatchdogDecisionRecord,
|
|
} from "./application/types.js";
|
|
export { WatchdogDecisionApplicationError } from "./application/types.js";
|