vona-core 5.0.105 → 5.0.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@cabloy/set';
|
|
2
2
|
import '@cabloy/json5';
|
|
3
|
-
import { combineApiPathControllerAndActionRaw, combineApiPathControllerAndAction, combineApiPath, combineResourceName, sleep, isUndefined, isClass, isNilOrEmptyString, evaluateExpressions, catchErrorSync, isEmptyObject, hashkey } from '@cabloy/utils';
|
|
3
|
+
import { combineApiPathControllerAndActionRaw, combineApiPathControllerAndAction, combineApiPath, combineResourceName, sleep, isUndefined, isClass, isNilOrEmptyString, evaluateExpressions, catchErrorSync, isEmptyObject, catchError, hashkey } from '@cabloy/utils';
|
|
4
4
|
import { toLowerCaseFirstChar, splitWords } from '@cabloy/word-utils';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import crypto from 'node:crypto';
|
|
@@ -348,7 +348,7 @@ async function saveJSONFile(fileName, json) {
|
|
|
348
348
|
function useApp() {
|
|
349
349
|
return globalThis.__app__;
|
|
350
350
|
}
|
|
351
|
-
async function closeApp(
|
|
351
|
+
async function closeApp() {
|
|
352
352
|
while (globalThis.__closing__) {
|
|
353
353
|
await sleep(50);
|
|
354
354
|
}
|
|
@@ -361,9 +361,6 @@ async function closeApp(terminate) {
|
|
|
361
361
|
} finally {
|
|
362
362
|
globalThis.__closing__ = false;
|
|
363
363
|
}
|
|
364
|
-
if (terminate) {
|
|
365
|
-
process.kill(process.pid, 'SIGTERM');
|
|
366
|
-
}
|
|
367
364
|
}
|
|
368
365
|
async function createGeneralApp(projectPath, envRuntime) {
|
|
369
366
|
if (envRuntime) {
|
|
@@ -2332,9 +2329,11 @@ class AppMeta extends BeanSimple {
|
|
|
2332
2329
|
// logger dispose
|
|
2333
2330
|
await this.app.meta.logger.dispose();
|
|
2334
2331
|
// log
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2332
|
+
if (this.app.meta.env.LOGGER_DUMMY !== 'true') {
|
|
2333
|
+
const message = `App shutdown gracefully: ${process.pid}`;
|
|
2334
|
+
// eslint-disable-next-line
|
|
2335
|
+
console.log(chalk.cyan(message));
|
|
2336
|
+
}
|
|
2338
2337
|
// need not call process.exit
|
|
2339
2338
|
}
|
|
2340
2339
|
}
|
|
@@ -2432,8 +2431,8 @@ class VonaApplication extends KoaApplication {
|
|
|
2432
2431
|
const response = res ?? new ResponseMock();
|
|
2433
2432
|
return this.createContext(request, response);
|
|
2434
2433
|
}
|
|
2435
|
-
async close(
|
|
2436
|
-
await closeApp(
|
|
2434
|
+
async close() {
|
|
2435
|
+
await closeApp();
|
|
2437
2436
|
}
|
|
2438
2437
|
}
|
|
2439
2438
|
|
|
@@ -2967,20 +2966,38 @@ function prepareAppInfo(env) {
|
|
|
2967
2966
|
};
|
|
2968
2967
|
}
|
|
2969
2968
|
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2969
|
+
let __sigintHandled = false;
|
|
2970
|
+
async function _closeAppInner() {
|
|
2971
|
+
const timeout = setTimeout(() => {
|
|
2972
|
+
// eslint-disable-next-line no-console
|
|
2973
|
+
console.log('Cleanup timed out. Forcing termination...');
|
|
2974
|
+
process.exit(1);
|
|
2975
|
+
}, 5000);
|
|
2976
|
+
const [_, err] = await catchError(() => {
|
|
2977
|
+
return closeApp();
|
|
2974
2978
|
});
|
|
2975
|
-
|
|
2979
|
+
if (err) {
|
|
2980
|
+
console.error(err);
|
|
2981
|
+
}
|
|
2982
|
+
clearTimeout(timeout);
|
|
2983
|
+
process.exit(err ? 1 : 0);
|
|
2984
|
+
}
|
|
2985
|
+
function handleProcessWork() {
|
|
2986
|
+
process.on('SIGINT', async () => {
|
|
2987
|
+
if (__sigintHandled) return;
|
|
2988
|
+
__sigintHandled = true;
|
|
2976
2989
|
// console.log('------------SIGINT');
|
|
2977
|
-
await
|
|
2990
|
+
await _closeAppInner();
|
|
2991
|
+
});
|
|
2992
|
+
process.on('SIGUSR2', async () => {
|
|
2993
|
+
// console.log('------------SIGUSR2');
|
|
2994
|
+
await _closeAppInner();
|
|
2978
2995
|
});
|
|
2979
2996
|
process.on('uncaughtException', async err => {
|
|
2980
2997
|
const app = useApp();
|
|
2981
2998
|
if (!app) {
|
|
2982
2999
|
console.error(err);
|
|
2983
|
-
process.
|
|
3000
|
+
process.exit(1);
|
|
2984
3001
|
} else {
|
|
2985
3002
|
const [logger] = catchErrorSync(() => {
|
|
2986
3003
|
return app.meta.logger.get();
|
|
@@ -2992,51 +3009,42 @@ function handleProcessWork() {
|
|
|
2992
3009
|
}
|
|
2993
3010
|
if (!app.meta.appStarted) {
|
|
2994
3011
|
await app.meta.logger.dispose();
|
|
2995
|
-
process.
|
|
3012
|
+
process.exit(1);
|
|
2996
3013
|
}
|
|
2997
3014
|
}
|
|
2998
3015
|
});
|
|
2999
3016
|
}
|
|
3000
3017
|
function handleProcessMaster() {
|
|
3001
|
-
process.
|
|
3002
|
-
//
|
|
3003
|
-
|
|
3018
|
+
process.on('SIGINT', () => {
|
|
3019
|
+
// donothing
|
|
3020
|
+
});
|
|
3021
|
+
process.on('SIGUSR2', () => {
|
|
3022
|
+
// donothing
|
|
3004
3023
|
});
|
|
3005
|
-
// should not kill master self by manual
|
|
3006
|
-
// process.once('SIGINT', () => {
|
|
3007
|
-
// process.kill(process.pid, 'SIGTERM');
|
|
3008
|
-
// });
|
|
3009
3024
|
}
|
|
3010
3025
|
|
|
3011
3026
|
async function startCluster(workers, bootstrapOptions) {
|
|
3012
3027
|
if (cluster.isPrimary) {
|
|
3013
3028
|
handleProcessMaster();
|
|
3014
3029
|
createAppMaster(bootstrapOptions);
|
|
3015
|
-
|
|
3016
|
-
// console.log(`Primary ${process.pid} is running`);
|
|
3017
|
-
|
|
3018
|
-
// Fork workers.
|
|
3019
3030
|
for (let i = 0; i < workers; i++) {
|
|
3020
3031
|
cluster.fork();
|
|
3021
3032
|
}
|
|
3022
3033
|
cluster.on('message', (worker, message) => {
|
|
3023
3034
|
if (message === 'reload-worker') {
|
|
3024
|
-
worker.process.kill('SIGTERM');
|
|
3025
3035
|
cluster.fork();
|
|
3036
|
+
worker.process.kill('SIGTERM');
|
|
3026
3037
|
}
|
|
3027
3038
|
});
|
|
3028
3039
|
cluster.on('exit', (_worker, _code, _signal) => {
|
|
3029
|
-
// console.log(
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
// process.kill(process.pid, 'SIGTERM');
|
|
3034
|
-
// }
|
|
3040
|
+
// console.log(`----------------- worker ${_worker.process.pid} died`, _code, _signal);
|
|
3041
|
+
if (cluster.workers && Object.keys(cluster.workers).length === 0) {
|
|
3042
|
+
process.exit(0);
|
|
3043
|
+
}
|
|
3035
3044
|
});
|
|
3036
3045
|
} else {
|
|
3037
3046
|
handleProcessWork();
|
|
3038
3047
|
await createApp(bootstrapOptions);
|
|
3039
|
-
// console.log(`Worker ${process.pid} started`);
|
|
3040
3048
|
}
|
|
3041
3049
|
}
|
|
3042
3050
|
|
|
@@ -27,5 +27,5 @@ export declare class VonaApplication extends KoaApplication {
|
|
|
27
27
|
/** get specific module's scope */
|
|
28
28
|
scope<K extends TypeBeanScopeRecordKeys>(moduleScope: K): IBeanScopeRecord[K];
|
|
29
29
|
createAnonymousContext(req?: any, res?: any): VonaContext;
|
|
30
|
-
close(
|
|
30
|
+
close(): Promise<void>;
|
|
31
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { VonaApplication } from '../core/application.ts';
|
|
2
2
|
export declare function useApp(): VonaApplication;
|
|
3
|
-
export declare function closeApp(
|
|
3
|
+
export declare function closeApp(): Promise<void>;
|
|
4
4
|
export declare function createGeneralApp(projectPath: string, envRuntime?: Partial<NodeJS.ProcessEnv>): Promise<any>;
|