Rewrite ~376 call sites for messages, runs, approvalsMod, and company domains and delete the corresponding pass-through methods on AppDatabase / AppDatabaseBase. Structural type references (ReturnType<HandlerDeps["db"]["getRun"]>) and SweepStaleReviewsDeps-style mocks are updated to route through the owning sub-module.
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import type { OrchestrationDependencies } from "./types";
|
|
import { createRunDispatch } from "./run-dispatch";
|
|
import { createHeartbeat } from "./heartbeat";
|
|
import { createScheduler } from "./scheduler";
|
|
import { createTaskRunner } from "./task-runner";
|
|
|
|
export function createOrchestrationService(deps: OrchestrationDependencies) {
|
|
const { db } = deps;
|
|
|
|
function hasActiveRun(filter: { taskId?: string; agentId?: string; companyId: string }) {
|
|
return db.runs.hasActiveRun(filter);
|
|
}
|
|
|
|
const runDispatch = createRunDispatch(deps);
|
|
const heartbeat = createHeartbeat(
|
|
deps,
|
|
runDispatch.resolveWorkspace,
|
|
runDispatch.getRunEligibilityFailure,
|
|
runDispatch.dispatchRunToWorker,
|
|
hasActiveRun,
|
|
);
|
|
const scheduler = createScheduler(
|
|
deps,
|
|
hasActiveRun,
|
|
heartbeat.startAgentHeartbeatRun,
|
|
heartbeat.wakeAgentIfPossible,
|
|
);
|
|
const taskRunner = createTaskRunner(
|
|
deps,
|
|
runDispatch.resolveWorkspace,
|
|
runDispatch.getRunEligibilityFailure,
|
|
runDispatch.dispatchRunToWorker,
|
|
hasActiveRun,
|
|
);
|
|
|
|
return {
|
|
resolveWorkspace: runDispatch.resolveWorkspace,
|
|
wakeAgentIfPossible: heartbeat.wakeAgentIfPossible,
|
|
dispatchRunToWorker: runDispatch.dispatchRunToWorker,
|
|
queueTaskRun: taskRunner.queueTaskRun,
|
|
resumeQueuedRuns: taskRunner.resumeQueuedRuns,
|
|
startAgentHeartbeatRun: heartbeat.startAgentHeartbeatRun,
|
|
startAllSchedulers: scheduler.startAllSchedulers,
|
|
stopAllSchedulers: scheduler.stopAllSchedulers,
|
|
};
|
|
}
|