BREAKING CHANGE(service): expand service lifecycle management with instance-aware hooks, startup timeouts, labels, readiness waits, and auto-restart support
This commit is contained in:
@@ -77,6 +77,23 @@ export class ServiceManager {
|
||||
// Build startup order via topological sort
|
||||
this.startupOrder = this.topologicalSort();
|
||||
this._startedAt = Date.now();
|
||||
|
||||
const startupPromise = this.startAllLevels();
|
||||
|
||||
// Enforce global startup timeout
|
||||
if (this.options.startupTimeoutMs) {
|
||||
await Promise.race([
|
||||
startupPromise,
|
||||
plugins.smartdelay.delayFor(this.options.startupTimeoutMs).then(() => {
|
||||
throw new Error(`${this.name}: global startup timeout exceeded (${this.options.startupTimeoutMs}ms)`);
|
||||
}),
|
||||
]);
|
||||
} else {
|
||||
await startupPromise;
|
||||
}
|
||||
}
|
||||
|
||||
private async startAllLevels(): Promise<void> {
|
||||
const startedServices: string[] = [];
|
||||
|
||||
logger.log('info', `${this.name}: starting ${this.services.size} services in ${this.startupOrder.length} levels`);
|
||||
@@ -178,6 +195,14 @@ export class ServiceManager {
|
||||
return Array.from(this.services.values()).map((s) => s.getStatus());
|
||||
}
|
||||
|
||||
public getServicesByLabel(key: string, value: string): Service[] {
|
||||
return Array.from(this.services.values()).filter((s) => s.labels[key] === value);
|
||||
}
|
||||
|
||||
public getServicesStatusByLabel(key: string, value: string): IServiceStatus[] {
|
||||
return this.getServicesByLabel(key, value).map((s) => s.getStatus());
|
||||
}
|
||||
|
||||
public getHealth(): IServiceManagerHealth {
|
||||
const statuses = this.getAllStatuses();
|
||||
let overall: TOverallHealth = 'healthy';
|
||||
|
||||
Reference in New Issue
Block a user