Files
OmniRoute/src/lib/services/registry.ts
Diego Rodrigues de Sa e Souza 78f09c8d9f Release v3.8.41 (#5327)
Release v3.8.41 — 52 commits since v3.8.40 (19 CHANGELOG bullets, 11 contributors).

All gating CI green: Unit×8, Coverage×8, Vitest, Package Artifact, Quality Ratchet, CodeQL, Lint, Docs Sync (Strict), Node 24/26 compat, E2E×9, Integration, Electron smoke.

Advisory checks overridden (main unprotected): PR Test Policy = test-masking heuristic on the cumulative 52-commit assert delta (legitimate dead-code-sweep removals + consolidations, reviewed per-PR); SonarCloud/SonarQube = new-code maintainability/coverage quality gate (CodeQL/Semgrep/Security/npm-audit/Dependabot all clean — not a security finding).
2026-06-29 16:51:03 -03:00

43 lines
1.5 KiB
TypeScript

/** Singleton registry of ServiceSupervisor instances. */
import type { ServiceSupervisor } from "./ServiceSupervisor";
const supervisors = new Map<string, ServiceSupervisor>();
export function registerSupervisor(supervisor: ServiceSupervisor): void {
supervisors.set(supervisor.getStatus().tool, supervisor);
}
export function getSupervisor(tool: string): ServiceSupervisor | null {
return supervisors.get(tool) ?? null;
}
/** Remove a supervisor by tool name. Intended for use in tests. */
export function unregisterSupervisor(tool: string): void {
supervisors.delete(tool);
}
async function stopAll(): Promise<void> {
// Drive every supervisor stop to completion before the process exits so the
// DB status writes inside ServiceSupervisor.stop() flush. Otherwise the
// event loop drains immediately on SIGTERM and rows are stuck in "running"
// or "starting" until the next boot.
await Promise.allSettled(Array.from(supervisors.values()).map((supervisor) => supervisor.stop()));
}
function handleShutdownSignal(signal: NodeJS.Signals): void {
stopAll()
.catch(() => {
/* never throw out of a signal handler */
})
.finally(() => {
// Re-raise the signal with the default disposition so the process exit
// status reflects the original signal (128 + signal number) rather than
// a synthetic process.exit() code.
process.kill(process.pid, signal);
});
}
process.once("SIGINT", () => handleShutdownSignal("SIGINT"));
process.once("SIGTERM", () => handleShutdownSignal("SIGTERM"));