mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-21 18:08:20 +08:00
feat(ql3): establish 3.0 incubation baseline
This commit is contained in:
+29
-3
@@ -23,6 +23,9 @@ class Application {
|
||||
private app: express.Application;
|
||||
private httpServerService?: HttpServerService;
|
||||
private grpcServerService?: GrpcServerService;
|
||||
private manualPrimaryRuntime?: {
|
||||
stop(): Promise<'drained' | 'timed_out'>;
|
||||
};
|
||||
private isShuttingDown = false;
|
||||
private workerMetadataMap = new Map<number, WorkerMetadata>();
|
||||
private httpWorker?: Worker;
|
||||
@@ -242,10 +245,18 @@ class Application {
|
||||
const appLoader = await import('./loaders/app');
|
||||
await appLoader.default({ app: this.app });
|
||||
|
||||
const server = await this.httpServerService.initialize(
|
||||
this.app,
|
||||
config.port,
|
||||
const { bootstrapDefaultManualPrimaryRuntime } = await import(
|
||||
'./runtime/adapters/legacy/bootstrapDefaultManualPrimaryRuntime'
|
||||
);
|
||||
this.manualPrimaryRuntime = await bootstrapDefaultManualPrimaryRuntime();
|
||||
|
||||
let server;
|
||||
try {
|
||||
server = await this.httpServerService.initialize(this.app, config.port);
|
||||
} catch (error) {
|
||||
await this.stopManualPrimaryRuntime();
|
||||
throw error;
|
||||
}
|
||||
|
||||
const serverLoader = await import('./loaders/server');
|
||||
await (serverLoader.default as any)({ server });
|
||||
@@ -289,6 +300,7 @@ class Application {
|
||||
|
||||
try {
|
||||
if (serviceType === 'http') {
|
||||
await this.stopManualPrimaryRuntime();
|
||||
await this.httpServerService?.shutdown();
|
||||
} else {
|
||||
await this.grpcServerService?.shutdown();
|
||||
@@ -299,6 +311,20 @@ class Application {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async stopManualPrimaryRuntime(): Promise<void> {
|
||||
const runtime = this.manualPrimaryRuntime;
|
||||
this.manualPrimaryRuntime = undefined;
|
||||
if (!runtime) return;
|
||||
try {
|
||||
const result = await runtime.stop();
|
||||
if (result === 'timed_out') {
|
||||
Logger.warn('[runtime-activation] shutdown timed out');
|
||||
}
|
||||
} catch {
|
||||
Logger.error('[runtime-activation] shutdown failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const app = new Application();
|
||||
|
||||
Reference in New Issue
Block a user