@yolo-croket-dev/core 1.4.53-slowquery.9 → 1.5.0
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/functions/amqp-call-manager.function.js +20 -9
- package/functions/amqp-handler.function.js +11 -9
- package/interceptors/logging-service.interceptor.js +24 -5
- package/interceptors/rpc.interceptor.d.ts +1 -3
- package/interceptors/rpc.interceptor.js +11 -53
- package/interfaces/http.d.ts +2 -0
- package/modules/index.d.ts +0 -1
- package/modules/index.js +0 -1
- package/package.json +2 -1
- package/modules/graceful-shutdown/graceful-shutdown.module.d.ts +0 -2
- package/modules/graceful-shutdown/graceful-shutdown.module.js +0 -21
- package/modules/graceful-shutdown/graceful-shutdown.rmq.d.ts +0 -20
- package/modules/graceful-shutdown/graceful-shutdown.rmq.js +0 -59
- package/modules/graceful-shutdown/graceful-shutdown.service.d.ts +0 -16
- package/modules/graceful-shutdown/graceful-shutdown.service.js +0 -81
|
@@ -26,12 +26,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.AmqpManagement = void 0;
|
|
27
27
|
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
28
28
|
const _1 = require(".");
|
|
29
|
+
const { SERVER_NAME } = process.env;
|
|
29
30
|
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
30
31
|
class AmqpManagement {
|
|
31
32
|
constructor(client) {
|
|
32
33
|
this.client = client;
|
|
33
34
|
}
|
|
34
|
-
paramProcessor(argParam, options) {
|
|
35
|
+
paramProcessor({ messagePattern, argParam, options, }) {
|
|
35
36
|
const param = { ...argParam };
|
|
36
37
|
if (!options) {
|
|
37
38
|
return param;
|
|
@@ -42,13 +43,19 @@ class AmqpManagement {
|
|
|
42
43
|
if (options.isCreateTraceId) {
|
|
43
44
|
param.traceId = (0, _1.generateTraceId)();
|
|
44
45
|
}
|
|
46
|
+
/** from 처리 */
|
|
47
|
+
param.from = `${SERVER_NAME}: ${messagePattern}`;
|
|
45
48
|
return param;
|
|
46
49
|
}
|
|
47
50
|
async call(funcName, messagePattern, payload, argParam, options) {
|
|
48
|
-
const param = this.paramProcessor(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const param = this.paramProcessor({
|
|
52
|
+
argParam: argParam || {
|
|
53
|
+
traceId: (0, _1.generateTraceId)(),
|
|
54
|
+
isInternal: true,
|
|
55
|
+
},
|
|
56
|
+
messagePattern,
|
|
57
|
+
options,
|
|
58
|
+
});
|
|
52
59
|
try {
|
|
53
60
|
const result = await (0, _1.AmqpHandler)(this.client, messagePattern, {
|
|
54
61
|
payload,
|
|
@@ -65,10 +72,14 @@ class AmqpManagement {
|
|
|
65
72
|
return undefined;
|
|
66
73
|
}
|
|
67
74
|
onlyPublish(funcName, messagePattern, payload, argParam, options) {
|
|
68
|
-
const param = this.paramProcessor(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
const param = this.paramProcessor({
|
|
76
|
+
argParam: argParam || {
|
|
77
|
+
traceId: (0, _1.generateTraceId)(),
|
|
78
|
+
isInternal: true,
|
|
79
|
+
},
|
|
80
|
+
options,
|
|
81
|
+
messagePattern,
|
|
82
|
+
});
|
|
72
83
|
this.client.emit(messagePattern, {
|
|
73
84
|
payload,
|
|
74
85
|
param,
|
|
@@ -5,6 +5,7 @@ const common_1 = require("@nestjs/common");
|
|
|
5
5
|
const rxjs_1 = require("rxjs");
|
|
6
6
|
const msa_logger_1 = require("@yolo-croket-dev/msa-logger");
|
|
7
7
|
const _1 = require(".");
|
|
8
|
+
const { SERVER_NAME } = process.env;
|
|
8
9
|
const msaLogger = new msa_logger_1.MsaLogger(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
9
10
|
class HttpExceptionCustom extends common_1.HttpException {
|
|
10
11
|
constructor(response, status, subMessage, errInfo) {
|
|
@@ -16,8 +17,13 @@ class HttpExceptionCustom extends common_1.HttpException {
|
|
|
16
17
|
exports.HttpExceptionCustom = HttpExceptionCustom;
|
|
17
18
|
// eslint-disable-next-line max-len
|
|
18
19
|
async function AmqpHandler(client, messagePattern, payload) {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
+
var _a, _b, _c, _d;
|
|
20
21
|
let data;
|
|
22
|
+
/** from 처리 */
|
|
23
|
+
if (!((_a = payload.param) === null || _a === void 0 ? void 0 : _a.from)) {
|
|
24
|
+
// eslint-disable-next-line no-param-reassign
|
|
25
|
+
payload.param.from = `${SERVER_NAME}: ${messagePattern}`;
|
|
26
|
+
}
|
|
21
27
|
try {
|
|
22
28
|
data = await (0, rxjs_1.lastValueFrom)(client.send(messagePattern, payload).pipe());
|
|
23
29
|
if (data.isError) {
|
|
@@ -27,7 +33,7 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
27
33
|
* 파일 객체 처리
|
|
28
34
|
* 다른 서비스에서 이미 처리가 될 수 있음
|
|
29
35
|
* */
|
|
30
|
-
(0, _1.reWriteFileValue)((
|
|
36
|
+
(0, _1.reWriteFileValue)((_b = data === null || data === void 0 ? void 0 : data.arg) === null || _b === void 0 ? void 0 : _b.file);
|
|
31
37
|
const errInfo = data.errInfo ? data.errInfo : {
|
|
32
38
|
message: data.errMessage,
|
|
33
39
|
type: data.errType,
|
|
@@ -45,18 +51,14 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
45
51
|
}
|
|
46
52
|
catch (err) {
|
|
47
53
|
if (typeof err === 'string' && err.includes('There is no matching message handler defined in the remote service.')) {
|
|
48
|
-
msaLogger.error('NOT_EXISTS_MESSAGE_PATTERN', {
|
|
49
|
-
traceId: ((_b = payload === null || payload === void 0 ? void 0 : payload.param) === null || _b === void 0 ? void 0 : _b.traceId) || '-'
|
|
50
|
-
}, { err });
|
|
54
|
+
msaLogger.error('NOT_EXISTS_MESSAGE_PATTERN', { traceId: ((_c = payload === null || payload === void 0 ? void 0 : payload.param) === null || _c === void 0 ? void 0 : _c.traceId) || '-' }, { err });
|
|
51
55
|
throw new HttpExceptionCustom('해당 메시지 패턴은 존재하지 않습니다.', 404, 'There is no matching message handler defined in the remote service.', {
|
|
52
56
|
type: 'NOT_EXISTS_MESSAGE_PATTERN',
|
|
53
|
-
message: '해당 메시지 패턴은 존재하지 않습니다.'
|
|
57
|
+
message: '해당 메시지 패턴은 존재하지 않습니다.',
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
else {
|
|
57
|
-
msaLogger.error('AMQP_HANDLER_ERROR', {
|
|
58
|
-
traceId: ((_c = payload === null || payload === void 0 ? void 0 : payload.param) === null || _c === void 0 ? void 0 : _c.traceId) || '-'
|
|
59
|
-
}, { err });
|
|
61
|
+
msaLogger.error('AMQP_HANDLER_ERROR', { traceId: ((_d = payload === null || payload === void 0 ? void 0 : payload.param) === null || _d === void 0 ? void 0 : _d.traceId) || '-' }, { err });
|
|
60
62
|
throw err;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -30,6 +30,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.LoggingServiceInterceptor = void 0;
|
|
33
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
33
34
|
/* eslint-disable no-param-reassign */
|
|
34
35
|
const common_1 = require("@nestjs/common");
|
|
35
36
|
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
@@ -68,15 +69,17 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
68
69
|
return data;
|
|
69
70
|
}
|
|
70
71
|
intercept(context, next) {
|
|
72
|
+
var _a;
|
|
71
73
|
const now = Date.now();
|
|
72
|
-
const args = context.getArgs();
|
|
73
|
-
const
|
|
74
|
+
// const args = context.getArgs();
|
|
75
|
+
const rmqContext = context.switchToRpc().getContext();
|
|
76
|
+
const originalMessage = rmqContext.getMessage();
|
|
74
77
|
const ctx = context.switchToHttp();
|
|
75
78
|
const request = ctx.getRequest();
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const content = JSON.parse(message.content.toString());
|
|
79
|
+
const originalcontent = originalMessage.content;
|
|
80
|
+
const content = JSON.parse(originalcontent.toString());
|
|
79
81
|
const traceId = content.data.param ? content.data.param.traceId : '-';
|
|
82
|
+
const from = ((_a = content.data.param) === null || _a === void 0 ? void 0 : _a.from) || '-';
|
|
80
83
|
msaLogger.printInputInterceptorService({
|
|
81
84
|
traceId,
|
|
82
85
|
messageBrokerInfo: {
|
|
@@ -84,6 +87,7 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
84
87
|
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
85
88
|
},
|
|
86
89
|
paramInfo: request.param,
|
|
90
|
+
traceInfo: { from },
|
|
87
91
|
});
|
|
88
92
|
return next.handle()
|
|
89
93
|
.pipe((0, operators_1.tap)(() => {
|
|
@@ -94,6 +98,11 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
94
98
|
status: 200,
|
|
95
99
|
ms: elapsed,
|
|
96
100
|
},
|
|
101
|
+
messageBrokerInfo: {
|
|
102
|
+
messagePatten: content.pattern,
|
|
103
|
+
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
104
|
+
},
|
|
105
|
+
traceInfo: { from },
|
|
97
106
|
});
|
|
98
107
|
})).pipe((0, operators_1.catchError)((error) => {
|
|
99
108
|
msaLogger.printExceptionFliterService({
|
|
@@ -104,6 +113,11 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
104
113
|
message: error.subMessage,
|
|
105
114
|
stack: error.stack,
|
|
106
115
|
},
|
|
116
|
+
messageBrokerInfo: {
|
|
117
|
+
messagePatten: content.pattern,
|
|
118
|
+
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
119
|
+
},
|
|
120
|
+
traceInfo: { from },
|
|
107
121
|
});
|
|
108
122
|
const elapsed = Date.now() - now;
|
|
109
123
|
msaLogger.printOutService({
|
|
@@ -112,6 +126,11 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
112
126
|
status: error.status,
|
|
113
127
|
ms: elapsed,
|
|
114
128
|
},
|
|
129
|
+
messageBrokerInfo: {
|
|
130
|
+
messagePatten: content.pattern,
|
|
131
|
+
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
132
|
+
},
|
|
133
|
+
traceInfo: { from },
|
|
115
134
|
});
|
|
116
135
|
throw error;
|
|
117
136
|
}));
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { ExecutionContext, NestInterceptor, CallHandler } from '@nestjs/common';
|
|
2
2
|
import { Reflector } from '@nestjs/core';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
-
import { GracefulShutdownService } from '../modules/graceful-shutdown/graceful-shutdown.service';
|
|
5
4
|
export declare class RPCInterceptor implements NestInterceptor {
|
|
6
5
|
private readonly reflector;
|
|
7
|
-
|
|
8
|
-
constructor(reflector: Reflector, gracefulShutdownService: GracefulShutdownService);
|
|
6
|
+
constructor(reflector: Reflector);
|
|
9
7
|
private maxLengthOverShorten;
|
|
10
8
|
private updateMaxLengthArrayShorten;
|
|
11
9
|
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<unknown>>;
|
|
@@ -1,56 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
10
|
};
|
|
34
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
12
|
exports.RPCInterceptor = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
36
14
|
/* eslint-disable no-param-reassign */
|
|
37
15
|
const common_1 = require("@nestjs/common");
|
|
38
16
|
const core_1 = require("@nestjs/core");
|
|
39
17
|
const rxjs_1 = require("rxjs");
|
|
40
18
|
const operators_1 = require("rxjs/operators");
|
|
41
|
-
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
42
19
|
// import Logger from '@yolo-croket-dev/logger';
|
|
43
20
|
const functions_1 = require("../functions");
|
|
44
21
|
const exceptions_1 = require("../exceptions");
|
|
45
|
-
const graceful_shutdown_service_1 = require("../modules/graceful-shutdown/graceful-shutdown.service");
|
|
46
|
-
// const logger = Logger.createLogger('RPCInterceptor');
|
|
47
|
-
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
48
22
|
// const MAX_CUT_LENGTH = 500;
|
|
49
23
|
const MAX_LENGTH = 300;
|
|
50
24
|
let RPCInterceptor = class RPCInterceptor {
|
|
51
|
-
constructor(reflector
|
|
25
|
+
constructor(reflector) {
|
|
52
26
|
this.reflector = reflector;
|
|
53
|
-
this.gracefulShutdownService = gracefulShutdownService;
|
|
54
27
|
}
|
|
55
28
|
maxLengthOverShorten(data) {
|
|
56
29
|
if (typeof data !== 'string') {
|
|
@@ -134,7 +107,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
134
107
|
// return data;
|
|
135
108
|
// }
|
|
136
109
|
async intercept(context, next) {
|
|
137
|
-
var _a
|
|
110
|
+
var _a;
|
|
138
111
|
const options = this.reflector.get('rpcInterceptorScope', context.getHandler());
|
|
139
112
|
const args = context.getArgs();
|
|
140
113
|
const arg = args[0];
|
|
@@ -146,25 +119,13 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
146
119
|
// const traceId = content.data.param ? content.data.param.traceId : null;
|
|
147
120
|
const isInternal = content.data.param ? content.data.param.isInternal : false;
|
|
148
121
|
const isAdmin = content.data.param ? content.data.param.isAdmin : false;
|
|
122
|
+
// const method = content.pattern;
|
|
149
123
|
const reDeliveryCount = Number(message.properties.headers['x-delivery-count']) || 0; /** 몇번 재전달되었는지 */
|
|
150
124
|
const staticRetryCount = Number(options === null || options === void 0 ? void 0 : options.messageRetryCount) || 0; /** 최대 재시도 갯수 */
|
|
151
|
-
const method = content.pattern;
|
|
152
|
-
const correlationId = message.properties.correlationId;
|
|
153
|
-
const execInterceptor = {
|
|
154
|
-
method,
|
|
155
|
-
traceId: ((_a = content.data.param) === null || _a === void 0 ? void 0 : _a.traceId) || '-',
|
|
156
|
-
correlationId,
|
|
157
|
-
};
|
|
158
125
|
// const logParam = {
|
|
159
126
|
// traceId,
|
|
160
127
|
// method,
|
|
161
128
|
// };
|
|
162
|
-
/** consume 메시지 전부 cancel */
|
|
163
|
-
if (this.gracefulShutdownService.isApplicationExit) {
|
|
164
|
-
msaLogger.debug('RPCInterceptor isApplicationExit called', { traceId: 'IS_APPLICATION_EXIT' });
|
|
165
|
-
channel.cancel(message.fields.consumerTag);
|
|
166
|
-
return new rxjs_1.Observable();
|
|
167
|
-
}
|
|
168
129
|
if (!staticRetryCount && reDeliveryCount > 0) {
|
|
169
130
|
channel.sendToQueue(message.properties.replyTo, Buffer.from(JSON.stringify({
|
|
170
131
|
isError: true,
|
|
@@ -205,8 +166,10 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
205
166
|
errMessage,
|
|
206
167
|
errAction,
|
|
207
168
|
};
|
|
208
|
-
|
|
209
|
-
|
|
169
|
+
if (!Number.isNaN(staticRetryCount)
|
|
170
|
+
&& staticRetryCount
|
|
171
|
+
&& err.isRetry !== false) {
|
|
172
|
+
/** 재시도 로직이 필요한 경우, 0보다 커야 정의된것. 기본값이 0, isRetry값이 false로 정의된 에러가 아니라면 전부 재시도 */
|
|
210
173
|
if (reDeliveryCount <= (staticRetryCount - 1)) { /** 재시도 횟수가 있고, 재시도 횟수보다 적을 경우, 0부터 카운팅 되므로 -1 */
|
|
211
174
|
channel.nack(message, false, true);
|
|
212
175
|
message.properties.replyTo = undefined; /** replyTo가 존재하면 sendToQueue가 호출되므로, 삭제해주기 */
|
|
@@ -243,7 +206,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
243
206
|
};
|
|
244
207
|
localErrorProcessor = localErrorProcessor.bind(this);
|
|
245
208
|
/** 파일 객체 처리 */
|
|
246
|
-
(0, functions_1.reWriteFileValue)((
|
|
209
|
+
(0, functions_1.reWriteFileValue)((_a = content === null || content === void 0 ? void 0 : content.data) === null || _a === void 0 ? void 0 : _a.file);
|
|
247
210
|
if (options) {
|
|
248
211
|
if (options.maxLengthKeys && options.maxLengthKeys.length) {
|
|
249
212
|
for (const key of options.maxLengthKeys) {
|
|
@@ -272,12 +235,10 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
272
235
|
else {
|
|
273
236
|
// logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
|
|
274
237
|
}
|
|
275
|
-
this.gracefulShutdownService.pushActiveInterceptors(execInterceptor);
|
|
276
238
|
// eslint-disable-next-line consistent-return
|
|
277
239
|
return next
|
|
278
240
|
.handle()
|
|
279
|
-
.pipe((0, operators_1.
|
|
280
|
-
(0, operators_1.tap)({
|
|
241
|
+
.pipe((0, operators_1.tap)({
|
|
281
242
|
next: async (val) => {
|
|
282
243
|
val.isError = false;
|
|
283
244
|
// const duration = Date.now() - now;
|
|
@@ -296,14 +257,11 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
296
257
|
}
|
|
297
258
|
},
|
|
298
259
|
error: localErrorProcessor,
|
|
299
|
-
}), (0, operators_1.finalize)(() => {
|
|
300
|
-
this.gracefulShutdownService.popActiveInterceptors(execInterceptor);
|
|
301
260
|
}));
|
|
302
261
|
}
|
|
303
262
|
};
|
|
304
263
|
exports.RPCInterceptor = RPCInterceptor;
|
|
305
264
|
exports.RPCInterceptor = RPCInterceptor = __decorate([
|
|
306
265
|
(0, common_1.Injectable)(),
|
|
307
|
-
__metadata("design:paramtypes", [core_1.Reflector
|
|
308
|
-
graceful_shutdown_service_1.GracefulShutdownService])
|
|
266
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
309
267
|
], RPCInterceptor);
|
package/interfaces/http.d.ts
CHANGED
package/modules/index.d.ts
CHANGED
package/modules/index.js
CHANGED
|
@@ -15,4 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./redis.module"), exports);
|
|
18
|
-
__exportStar(require("./graceful-shutdown/graceful-shutdown.module"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolo-croket-dev/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": "Yolo Co., Ltd.",
|
|
5
5
|
"description": "Yolo commonization module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@nestjs/common": "^8.2.3",
|
|
18
18
|
"@nestjs/microservices": "9.0.8",
|
|
19
19
|
"@yolo-croket-dev/logger": "^1.0.15",
|
|
20
|
+
"@yolo-croket-dev/msa-logger": "^2.1.0",
|
|
20
21
|
"@yolo-croket-dev/redis": "^1.0.23",
|
|
21
22
|
"@yolo-croket-dev/swagger": "^0.0.7",
|
|
22
23
|
"axios": "^1.1.3",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.GracefulShutdownModule = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const graceful_shutdown_service_1 = require("./graceful-shutdown.service");
|
|
12
|
-
let GracefulShutdownModule = class GracefulShutdownModule {
|
|
13
|
-
};
|
|
14
|
-
exports.GracefulShutdownModule = GracefulShutdownModule;
|
|
15
|
-
exports.GracefulShutdownModule = GracefulShutdownModule = __decorate([
|
|
16
|
-
(0, common_1.Global)(),
|
|
17
|
-
(0, common_1.Module)({
|
|
18
|
-
providers: [graceful_shutdown_service_1.GracefulShutdownService],
|
|
19
|
-
exports: [graceful_shutdown_service_1.GracefulShutdownService],
|
|
20
|
-
})
|
|
21
|
-
], GracefulShutdownModule);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { RmqOptions, ServerRMQ } from '@nestjs/microservices';
|
|
2
|
-
import { Channel } from 'amqp-connection-manager';
|
|
3
|
-
import { ConsumeMessage } from 'amqplib';
|
|
4
|
-
export type GracefulRmqOptions = RmqOptions['options'] & {
|
|
5
|
-
waitingEndingHandlersTimeoutMs?: number;
|
|
6
|
-
waitingEndingHandlersIntervalMs?: number;
|
|
7
|
-
};
|
|
8
|
-
export declare class GracefulServerRMQ extends ServerRMQ {
|
|
9
|
-
protected readonly options: GracefulRmqOptions;
|
|
10
|
-
protected runningMessages: number;
|
|
11
|
-
protected closing: boolean;
|
|
12
|
-
protected consumerTag: string | null;
|
|
13
|
-
protected readonly waitingEndingHandlersTimeoutMs: number;
|
|
14
|
-
protected readonly waitingEndingHandlersIntervalMs: number;
|
|
15
|
-
constructor(options: GracefulRmqOptions);
|
|
16
|
-
setupChannel(channel: Channel, callback: () => void): Promise<void>;
|
|
17
|
-
protected waitingHandlers(): Promise<void>;
|
|
18
|
-
handleMessage(message: ConsumeMessage, channel: Channel): Promise<void>;
|
|
19
|
-
close(): Promise<void>;
|
|
20
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GracefulServerRMQ = void 0;
|
|
4
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
-
const node_util_1 = require("node:util");
|
|
6
|
-
const sleep = (0, node_util_1.promisify)(setTimeout);
|
|
7
|
-
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_TIMEOUT_MS = 5000;
|
|
8
|
-
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_INTERVAL_MS = 500;
|
|
9
|
-
class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
super(options);
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.runningMessages = 0;
|
|
14
|
-
this.closing = false;
|
|
15
|
-
this.consumerTag = null;
|
|
16
|
-
this.waitingEndingHandlersTimeoutMs = this.getOptionsProp(this.options, 'waitingEndingHandlersTimeoutMs')
|
|
17
|
-
|| RMQ_DEFAULT_WAITING_ENDING_HANDLERS_TIMEOUT_MS;
|
|
18
|
-
this.waitingEndingHandlersIntervalMs = this.getOptionsProp(this.options, 'waitingEndingHandlersIntervalMs')
|
|
19
|
-
|| RMQ_DEFAULT_WAITING_ENDING_HANDLERS_INTERVAL_MS;
|
|
20
|
-
}
|
|
21
|
-
async setupChannel(channel, callback) {
|
|
22
|
-
if (this.closing) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (!this.queueOptions.noAssert) {
|
|
26
|
-
await channel.assertQueue(this.queue, this.queueOptions);
|
|
27
|
-
}
|
|
28
|
-
await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);
|
|
29
|
-
const { consumerTag } = await channel.consume(this.queue, (msg) => this.handleMessage(msg, channel), { noAck: false });
|
|
30
|
-
this.consumerTag = consumerTag;
|
|
31
|
-
callback();
|
|
32
|
-
}
|
|
33
|
-
async waitingHandlers() {
|
|
34
|
-
while (this.runningMessages > 0) {
|
|
35
|
-
await sleep(this.waitingEndingHandlersIntervalMs);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async handleMessage(message, channel) {
|
|
39
|
-
this.runningMessages += 1;
|
|
40
|
-
return super.handleMessage(message, channel).finally(() => {
|
|
41
|
-
this.runningMessages -= 1;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async close() {
|
|
45
|
-
this.closing = true;
|
|
46
|
-
if (this.channel) {
|
|
47
|
-
await this.channel.removeSetup(undefined, (channel) => channel.cancel(this.consumerTag));
|
|
48
|
-
}
|
|
49
|
-
this.consumerTag = null;
|
|
50
|
-
await Promise.race([
|
|
51
|
-
this.waitingHandlers(),
|
|
52
|
-
this.waitingEndingHandlersTimeoutMs > 0
|
|
53
|
-
&& sleep(this.waitingEndingHandlersTimeoutMs),
|
|
54
|
-
]);
|
|
55
|
-
this.runningMessages = 0;
|
|
56
|
-
super.close();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.GracefulServerRMQ = GracefulServerRMQ;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { OnApplicationShutdown, OnModuleDestroy, OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
-
interface GracefulExecInterceptor {
|
|
3
|
-
method: string;
|
|
4
|
-
traceId?: string;
|
|
5
|
-
correlationId: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class GracefulShutdownService implements OnApplicationShutdown, OnModuleDestroy, OnApplicationBootstrap {
|
|
8
|
-
private activeInterceptors;
|
|
9
|
-
isApplicationExit: boolean;
|
|
10
|
-
onApplicationBootstrap(): void;
|
|
11
|
-
pushActiveInterceptors(execInterceptor: GracefulExecInterceptor): void;
|
|
12
|
-
popActiveInterceptors(execInterceptor: GracefulExecInterceptor): void;
|
|
13
|
-
onApplicationShutdown(signal?: string): Promise<void>;
|
|
14
|
-
onModuleDestroy(): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.GracefulShutdownService = void 0;
|
|
33
|
-
const common_1 = require("@nestjs/common");
|
|
34
|
-
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
35
|
-
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
36
|
-
let GracefulShutdownService = class GracefulShutdownService {
|
|
37
|
-
constructor() {
|
|
38
|
-
this.activeInterceptors = [];
|
|
39
|
-
this.isApplicationExit = false;
|
|
40
|
-
}
|
|
41
|
-
onApplicationBootstrap() {
|
|
42
|
-
this.activeInterceptors = [];
|
|
43
|
-
}
|
|
44
|
-
pushActiveInterceptors(execInterceptor) {
|
|
45
|
-
this.activeInterceptors.push(execInterceptor);
|
|
46
|
-
}
|
|
47
|
-
popActiveInterceptors(execInterceptor) {
|
|
48
|
-
// eslint-disable-next-line max-len
|
|
49
|
-
this.activeInterceptors = this.activeInterceptors.filter((item) => item.method === execInterceptor.method && item.traceId === execInterceptor.traceId && item.correlationId === execInterceptor.correlationId);
|
|
50
|
-
}
|
|
51
|
-
async onApplicationShutdown(signal) {
|
|
52
|
-
console.debug(`GracefulShutdownService.onApplicationShutdown signal=${signal}`, { traceId: 'ON_APPLICATION_SHUTDOWN' });
|
|
53
|
-
msaLogger.debug(`GracefulShutdownService.onApplicationShutdown signal=${signal}`, { traceId: 'ON_APPLICATION_SHUTDOWN' });
|
|
54
|
-
process.exit(0);
|
|
55
|
-
}
|
|
56
|
-
async onModuleDestroy() {
|
|
57
|
-
this.isApplicationExit = true;
|
|
58
|
-
msaLogger.debug('GracefulShutdownService.onModuleDestroy', { traceId: 'ON_MODULE_DESTROY' });
|
|
59
|
-
// eslint-disable-next-line max-len
|
|
60
|
-
msaLogger.debug('GracefulShutdownService.onModuleDestroy activeInterceptors', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
61
|
-
// eslint-disable-next-line max-len
|
|
62
|
-
console.debug('GracefulShutdownService.onModuleDestroy activeInterceptors', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
63
|
-
let prevExecInterceptorCount = 0;
|
|
64
|
-
while (this.activeInterceptors.length) {
|
|
65
|
-
if (prevExecInterceptorCount !== this.activeInterceptors.length) {
|
|
66
|
-
prevExecInterceptorCount = this.activeInterceptors.length;
|
|
67
|
-
// eslint-disable-next-line max-len
|
|
68
|
-
console.log(`GracefulShutdownService.onModuleDestroy: waiting for ${this.activeInterceptors} interceptors to finish`, { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
69
|
-
// eslint-disable-next-line max-len
|
|
70
|
-
msaLogger.debug(`GracefulShutdownService.onModuleDestroy: waiting for ${this.activeInterceptors} interceptors to finish`, { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
71
|
-
}
|
|
72
|
-
await new Promise((resolve) => {
|
|
73
|
-
setTimeout(resolve, 1000);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
exports.GracefulShutdownService = GracefulShutdownService;
|
|
79
|
-
exports.GracefulShutdownService = GracefulShutdownService = __decorate([
|
|
80
|
-
(0, common_1.Injectable)()
|
|
81
|
-
], GracefulShutdownService);
|