fix: host imports running a defaults pass and metrics restart per host (#1384)

This commit is contained in:
LukeGus committed 2026-10-03 15:37:07 -05:00
1 parent 5e31642379
commit 11a22d30eb
6 files changed
+76 -10

No files matched your search

+15 -1
View File
@@ -22,6 +22,8 @@ export interface MetricsViewersV1 {
unregister: (hostId: number, viewerSessionId: string) => void;
}
const RETIME_DEBOUNCE_MS = 1000;
export async function activate(ctx: PluginContext) {
const log = createLogger(ctx.log);
const repository = await createHostMetricsRepository(ctx.db);
@@ -73,7 +75,19 @@ export async function activate(ctx: PluginContext) {
const { hostId } = payload as { hostId?: number };
if (hostId) poller.hostKeyAccepted(hostId);
});
ctx.settings.onChange("metricsInterval", () => void poller.retimeAll());
// An import writes this once per host, and each write restarted every
// polled host. One retime after the writes settle covers them all.
let retime: ReturnType<typeof setTimeout> | null = null;
ctx.settings.onChange("metricsInterval", () => {
if (retime) clearTimeout(retime);
retime = setTimeout(() => {
retime = null;
void poller.retimeAll();
}, RETIME_DEBOUNCE_MS);
});
ctx.disposables.add(() => {
if (retime) clearTimeout(retime);
});
ctx.services.provide<MetricsViewersV1>("host-metrics.viewers", {
register: async (hostId) => {