feat: implement telemetry system for application usage tracking
- Added telemetry utility to capture application events and metrics. - Integrated PostHog for event tracking with distinct user identification. - Implemented telemetry initialization, event capturing, and shutdown procedures. feat: add UV environment setup for Python management - Created utilities to manage Python installation and configuration. - Implemented network optimization checks for Python installation mirrors. - Added functions to set up managed Python environments with error handling. feat: enhance host API communication with token management - Introduced host API token retrieval and management for secure requests. - Updated host API fetch functions to include token in headers. - Added support for creating event sources with authentication. test: add comprehensive tests for gateway protocol and startup helpers - Implemented unit tests for gateway protocol helpers, event dispatching, and state management. - Added tests for startup recovery strategies and process policies. - Ensured coverage for connection monitoring and restart governance logic.
This commit is contained in:
31
electron/gateway/lifecycle-controller.ts
Normal file
31
electron/gateway/lifecycle-controller.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import logManager from '@electron/service/logger';
|
||||
import { isLifecycleSuperseded, nextLifecycleEpoch } from './process-policy';
|
||||
|
||||
export class LifecycleSupersededError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'LifecycleSupersededError';
|
||||
}
|
||||
}
|
||||
|
||||
export class GatewayLifecycleController {
|
||||
private epoch = 0;
|
||||
|
||||
getCurrentEpoch(): number {
|
||||
return this.epoch;
|
||||
}
|
||||
|
||||
bump(reason: string): number {
|
||||
this.epoch = nextLifecycleEpoch(this.epoch);
|
||||
logManager.debug(`Gateway lifecycle epoch advanced to ${this.epoch} (${reason})`);
|
||||
return this.epoch;
|
||||
}
|
||||
|
||||
assert(expectedEpoch: number, phase: string): void {
|
||||
if (isLifecycleSuperseded(expectedEpoch, this.epoch)) {
|
||||
throw new LifecycleSupersededError(
|
||||
`Gateway ${phase} superseded (expectedEpoch=${expectedEpoch}, currentEpoch=${this.epoch})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user