feat(companion): add heartbeat loop getState snapshot

This commit is contained in:
William Valentin
2026-02-16 19:12:47 -08:00
parent 636f24016f
commit 1fb70ce0b1
5 changed files with 35 additions and 1 deletions
+5
View File
@@ -191,5 +191,10 @@ describe('CompanionHeartbeatLoop', () => {
await loop.tickNow();
expect(publishHeartbeat).toHaveBeenCalledTimes(1);
expect(loop.running).toBe(false);
expect(loop.getState()).toEqual({
running: false,
failureCount: 0,
lastFailure: null,
});
});
});
+14
View File
@@ -16,6 +16,12 @@ export interface CompanionHeartbeatLoopOptions {
randomFn?: () => number;
}
export interface CompanionHeartbeatLoopState {
running: boolean;
failureCount: number;
lastFailure: Error | null;
}
/**
* Lightweight periodic heartbeat loop for companion runtimes.
* Calls `publishHeartbeat` on a fixed interval with optional dynamic payload generation.
@@ -77,6 +83,14 @@ export class CompanionHeartbeatLoop {
return this.lastError;
}
getState(): CompanionHeartbeatLoopState {
return {
running: this.running,
failureCount: this.failureCount,
lastFailure: this.lastFailure,
};
}
start(runImmediately = true): void {
if (this.started) {
return;
+1
View File
@@ -57,4 +57,5 @@ export type {
export type {
HeartbeatPublisher,
CompanionHeartbeatLoopOptions,
CompanionHeartbeatLoopState,
} from './heartbeatLoop.js';