perf: Health snapshot changes
This commit is contained in:
@@ -57,6 +57,12 @@ export interface DesktopUpdateServerContext {
|
||||
serverVersionStatus: DesktopUpdateServerVersionStatus;
|
||||
}
|
||||
|
||||
export interface DesktopUpdateServerHealthSnapshot {
|
||||
manifestUrl: string | null;
|
||||
serverVersion: string | null;
|
||||
serverVersionStatus: DesktopUpdateServerVersionStatus;
|
||||
}
|
||||
|
||||
export interface DesktopUpdateState {
|
||||
autoUpdateMode: AutoUpdateMode;
|
||||
availableVersions: string[];
|
||||
@@ -127,6 +133,7 @@ export interface ElectronApi {
|
||||
consumePendingDeepLink: () => Promise<string | null>;
|
||||
getDesktopSettings: () => Promise<DesktopSettingsSnapshot>;
|
||||
getAutoUpdateState: () => Promise<DesktopUpdateState>;
|
||||
getAutoUpdateServerHealth: (serverUrl: string) => Promise<DesktopUpdateServerHealthSnapshot>;
|
||||
configureAutoUpdateContext: (context: Partial<DesktopUpdateServerContext>) => Promise<DesktopUpdateState>;
|
||||
checkForAppUpdates: () => Promise<DesktopUpdateState>;
|
||||
restartToApplyUpdate: () => Promise<boolean>;
|
||||
|
||||
@@ -10,17 +10,13 @@ import { type ServerEndpoint, ServerDirectoryFacade } from '../../domains/server
|
||||
import {
|
||||
type AutoUpdateMode,
|
||||
type DesktopUpdateServerContext,
|
||||
type DesktopUpdateServerHealthSnapshot,
|
||||
type DesktopUpdateServerVersionStatus,
|
||||
type DesktopUpdateState,
|
||||
type ElectronApi
|
||||
} from '../platform/electron/electron-api.models';
|
||||
import { ElectronBridgeService } from '../platform/electron/electron-bridge.service';
|
||||
|
||||
interface ServerHealthResponse {
|
||||
releaseManifestUrl?: string;
|
||||
serverVersion?: string;
|
||||
}
|
||||
|
||||
interface ServerHealthSnapshot {
|
||||
endpointId: string;
|
||||
manifestUrl: string | null;
|
||||
@@ -29,7 +25,6 @@ interface ServerHealthSnapshot {
|
||||
}
|
||||
|
||||
const SERVER_CONTEXT_REFRESH_INTERVAL_MS = 5 * 60_000;
|
||||
const SERVER_CONTEXT_TIMEOUT_MS = 5_000;
|
||||
|
||||
function createInitialState(): DesktopUpdateState {
|
||||
return {
|
||||
@@ -292,30 +287,23 @@ export class DesktopAppUpdateService {
|
||||
|
||||
private async readServerHealth(endpoint: ServerEndpoint): Promise<ServerHealthSnapshot> {
|
||||
const sanitizedServerUrl = endpoint.url.replace(/\/+$/, '');
|
||||
const api = this.getElectronApi();
|
||||
|
||||
if (!api?.getAutoUpdateServerHealth) {
|
||||
return {
|
||||
endpointId: endpoint.id,
|
||||
manifestUrl: null,
|
||||
serverVersion: null,
|
||||
serverVersionStatus: 'unavailable'
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${sanitizedServerUrl}/api/health`, {
|
||||
method: 'GET',
|
||||
signal: AbortSignal.timeout(SERVER_CONTEXT_TIMEOUT_MS)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
endpointId: endpoint.id,
|
||||
manifestUrl: null,
|
||||
serverVersion: null,
|
||||
serverVersionStatus: 'unavailable'
|
||||
};
|
||||
}
|
||||
|
||||
const payload = await response.json() as ServerHealthResponse;
|
||||
const serverVersion = normalizeOptionalString(payload.serverVersion);
|
||||
const payload = await api.getAutoUpdateServerHealth(sanitizedServerUrl);
|
||||
|
||||
return {
|
||||
endpointId: endpoint.id,
|
||||
manifestUrl: normalizeOptionalHttpUrl(payload.releaseManifestUrl),
|
||||
serverVersion,
|
||||
serverVersionStatus: serverVersion ? 'reported' : 'missing'
|
||||
...this.normalizeHealthSnapshot(payload)
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
@@ -327,6 +315,22 @@ export class DesktopAppUpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
private normalizeHealthSnapshot(
|
||||
snapshot: DesktopUpdateServerHealthSnapshot
|
||||
): Omit<ServerHealthSnapshot, 'endpointId'> {
|
||||
const serverVersion = normalizeOptionalString(snapshot.serverVersion);
|
||||
|
||||
return {
|
||||
manifestUrl: normalizeOptionalHttpUrl(snapshot.manifestUrl),
|
||||
serverVersion,
|
||||
serverVersionStatus: serverVersion
|
||||
? snapshot.serverVersionStatus
|
||||
: snapshot.serverVersionStatus === 'reported'
|
||||
? 'missing'
|
||||
: snapshot.serverVersionStatus
|
||||
};
|
||||
}
|
||||
|
||||
private async pushContext(context: Partial<DesktopUpdateServerContext>): Promise<void> {
|
||||
const api = this.getElectronApi();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user