mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-18 18:33:06 +08:00
Download updates asynchronously with persistent progress and validate matching source and build artifacts before an explicit restart. Keep upgrade workers alive across service restarts, verify the new runtime, and recover the browser with a one-time success notice. Publish immutable archive sizes and checksums for accurate download progress. Align the update dialog, hide unavailable actions during transfers, and show the sidebar notice only for active, ready or failed jobs. Constrain long account names with ellipsis while preserving avatar and collapse controls.
72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import { Service } from 'typedi';
|
|
import Logger from '../loaders/logger';
|
|
import cronClient from '../schedule/client';
|
|
import { HttpServerService } from './http';
|
|
import { runtimeBuild } from '../shared/runtimeBuild';
|
|
|
|
interface HealthStatus {
|
|
build: typeof runtimeBuild;
|
|
status: 'ok' | 'error';
|
|
services: {
|
|
http: boolean;
|
|
grpc: boolean;
|
|
};
|
|
metrics: {
|
|
uptime: number;
|
|
memory: {
|
|
used: number;
|
|
total: number;
|
|
};
|
|
};
|
|
}
|
|
|
|
@Service()
|
|
export class HealthService {
|
|
private startTime = Date.now();
|
|
|
|
constructor(private httpServerService: HttpServerService) {}
|
|
|
|
async check(): Promise<HealthStatus> {
|
|
const status: HealthStatus = {
|
|
build: runtimeBuild,
|
|
status: 'ok',
|
|
services: {
|
|
http: true,
|
|
grpc: true,
|
|
},
|
|
metrics: {
|
|
uptime: Math.floor((Date.now() - this.startTime) / 1000),
|
|
memory: {
|
|
used: process.memoryUsage().heapUsed,
|
|
total: process.memoryUsage().heapTotal,
|
|
},
|
|
},
|
|
};
|
|
|
|
try {
|
|
const httpServer = this.httpServerService.getServer();
|
|
if (!httpServer) {
|
|
status.services.http = false;
|
|
status.status = 'error';
|
|
}
|
|
} catch (err) {
|
|
status.services.http = false;
|
|
status.status = 'error';
|
|
Logger.error('HTTP server check failed:', err);
|
|
}
|
|
|
|
try {
|
|
if (!(await cronClient.readiness.check())) {
|
|
status.services.grpc = false;
|
|
status.status = 'error';
|
|
}
|
|
} catch (err) {
|
|
status.services.grpc = false;
|
|
status.status = 'error';
|
|
Logger.error('gRPC server check failed:', err);
|
|
}
|
|
|
|
return status;
|
|
}
|
|
}
|