@yolo-croket-dev/core 1.4.53-slowquery.13 → 1.4.53-slowquery.3
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/interceptors/rpc.interceptor.js +8 -19
- package/modules/graceful-shutdown/graceful-shutdown.module.js +0 -1
- package/modules/graceful-shutdown/graceful-shutdown.service.d.ts +4 -12
- package/modules/graceful-shutdown/graceful-shutdown.service.js +19 -28
- package/package.json +1 -1
- package/modules/graceful-shutdown/graceful-shutdown.rmq.d.ts +0 -20
- package/modules/graceful-shutdown/graceful-shutdown.rmq.js +0 -59
|
@@ -134,7 +134,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
134
134
|
// return data;
|
|
135
135
|
// }
|
|
136
136
|
async intercept(context, next) {
|
|
137
|
-
var _a
|
|
137
|
+
var _a;
|
|
138
138
|
const options = this.reflector.get('rpcInterceptorScope', context.getHandler());
|
|
139
139
|
const args = context.getArgs();
|
|
140
140
|
const arg = args[0];
|
|
@@ -146,25 +146,13 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
146
146
|
// const traceId = content.data.param ? content.data.param.traceId : null;
|
|
147
147
|
const isInternal = content.data.param ? content.data.param.isInternal : false;
|
|
148
148
|
const isAdmin = content.data.param ? content.data.param.isAdmin : false;
|
|
149
|
+
// const method = content.pattern;
|
|
149
150
|
const reDeliveryCount = Number(message.properties.headers['x-delivery-count']) || 0; /** 몇번 재전달되었는지 */
|
|
150
151
|
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
152
|
// const logParam = {
|
|
159
153
|
// traceId,
|
|
160
154
|
// method,
|
|
161
155
|
// };
|
|
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
156
|
if (!staticRetryCount && reDeliveryCount > 0) {
|
|
169
157
|
channel.sendToQueue(message.properties.replyTo, Buffer.from(JSON.stringify({
|
|
170
158
|
isError: true,
|
|
@@ -243,7 +231,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
243
231
|
};
|
|
244
232
|
localErrorProcessor = localErrorProcessor.bind(this);
|
|
245
233
|
/** 파일 객체 처리 */
|
|
246
|
-
(0, functions_1.reWriteFileValue)((
|
|
234
|
+
(0, functions_1.reWriteFileValue)((_a = content === null || content === void 0 ? void 0 : content.data) === null || _a === void 0 ? void 0 : _a.file);
|
|
247
235
|
if (options) {
|
|
248
236
|
if (options.maxLengthKeys && options.maxLengthKeys.length) {
|
|
249
237
|
for (const key of options.maxLengthKeys) {
|
|
@@ -272,12 +260,12 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
272
260
|
else {
|
|
273
261
|
// logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
|
|
274
262
|
}
|
|
275
|
-
|
|
263
|
+
msaLogger.debug('RPCInterceptor IncActiveInterceptors called', { traceId: 'INC_RPC_ACTIVE_INTERCEPTORS' });
|
|
264
|
+
this.gracefulShutdownService.incActiveInterceptors();
|
|
276
265
|
// eslint-disable-next-line consistent-return
|
|
277
266
|
return next
|
|
278
267
|
.handle()
|
|
279
|
-
.pipe((0, operators_1.
|
|
280
|
-
(0, operators_1.tap)({
|
|
268
|
+
.pipe((0, operators_1.tap)({
|
|
281
269
|
next: async (val) => {
|
|
282
270
|
val.isError = false;
|
|
283
271
|
// const duration = Date.now() - now;
|
|
@@ -297,7 +285,8 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
297
285
|
},
|
|
298
286
|
error: localErrorProcessor,
|
|
299
287
|
}), (0, operators_1.finalize)(() => {
|
|
300
|
-
|
|
288
|
+
msaLogger.debug('RPCInterceptor DecActiveInterceptors called', { traceId: 'DEC_RPC_ACTIVE_INTERCEPTORS' });
|
|
289
|
+
this.gracefulShutdownService.decActiveInterceptors();
|
|
301
290
|
}));
|
|
302
291
|
}
|
|
303
292
|
};
|
|
@@ -13,7 +13,6 @@ let GracefulShutdownModule = class GracefulShutdownModule {
|
|
|
13
13
|
};
|
|
14
14
|
exports.GracefulShutdownModule = GracefulShutdownModule;
|
|
15
15
|
exports.GracefulShutdownModule = GracefulShutdownModule = __decorate([
|
|
16
|
-
(0, common_1.Global)(),
|
|
17
16
|
(0, common_1.Module)({
|
|
18
17
|
providers: [graceful_shutdown_service_1.GracefulShutdownService],
|
|
19
18
|
exports: [graceful_shutdown_service_1.GracefulShutdownService],
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { OnApplicationShutdown, OnModuleDestroy
|
|
2
|
-
|
|
3
|
-
method: string;
|
|
4
|
-
traceId?: string;
|
|
5
|
-
correlationId: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class GracefulShutdownService implements OnApplicationShutdown, OnModuleDestroy, OnApplicationBootstrap {
|
|
1
|
+
import { OnApplicationShutdown, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
export declare class GracefulShutdownService implements OnApplicationShutdown, OnModuleDestroy {
|
|
8
3
|
private activeInterceptors;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
pushActiveInterceptors(execInterceptor: GracefulExecInterceptor): void;
|
|
12
|
-
popActiveInterceptors(execInterceptor: GracefulExecInterceptor): void;
|
|
4
|
+
incActiveInterceptors(): void;
|
|
5
|
+
decActiveInterceptors(): void;
|
|
13
6
|
onApplicationShutdown(signal?: string): Promise<void>;
|
|
14
7
|
onModuleDestroy(): Promise<void>;
|
|
15
8
|
}
|
|
16
|
-
export {};
|
|
@@ -35,42 +35,33 @@ const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
|
35
35
|
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
36
36
|
let GracefulShutdownService = class GracefulShutdownService {
|
|
37
37
|
constructor() {
|
|
38
|
-
this.activeInterceptors =
|
|
39
|
-
this.isApplicationExit = false;
|
|
38
|
+
this.activeInterceptors = 0;
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
this.activeInterceptors
|
|
40
|
+
incActiveInterceptors() {
|
|
41
|
+
this.activeInterceptors += 1;
|
|
42
|
+
msaLogger.debug(`GracefulShutdownService.incActiveInterceptors: ${this.activeInterceptors}`, { traceId: 'INC_ACTIVE_INTERCEPTORS' });
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
this.activeInterceptors
|
|
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));
|
|
44
|
+
decActiveInterceptors() {
|
|
45
|
+
this.activeInterceptors -= 1;
|
|
46
|
+
msaLogger.debug(`GracefulShutdownService.decActiveInterceptors: ${this.activeInterceptors}`, { traceId: 'DEC_ACTIVE_INTERCEPTORS' });
|
|
50
47
|
}
|
|
51
48
|
async onApplicationShutdown(signal) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
msaLogger.debug(`GracefulShutdownService.onApplicationShutdown: ${signal}`, { traceId: 'ON_APPLICATION_SHUTDOWN' });
|
|
50
|
+
while (this.activeInterceptors > 0) {
|
|
51
|
+
// eslint-disable-next-line max-len
|
|
52
|
+
msaLogger.debug(`GracefulShutdownService.onApplicationShutdown: waiting for ${this.activeInterceptors} interceptors to finish`, { traceId: 'ON_APPLICATION_SHUTDOWN' });
|
|
53
|
+
await new Promise((resolve) => {
|
|
54
|
+
setTimeout(resolve, 100);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
async onModuleDestroy() {
|
|
57
|
-
this.isApplicationExit = true;
|
|
58
59
|
msaLogger.debug('GracefulShutdownService.onModuleDestroy', { traceId: 'ON_MODULE_DESTROY' });
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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 interceptors to finish', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
69
|
-
// eslint-disable-next-line max-len
|
|
70
|
-
msaLogger.debug('GracefulShutdownService.onModuleDestroy: waiting for interceptors to finish', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
71
|
-
}
|
|
60
|
+
while (this.activeInterceptors > 0) {
|
|
61
|
+
// eslint-disable-next-line max-len
|
|
62
|
+
msaLogger.debug(`GracefulShutdownService.onModuleDestroy: waiting for ${this.activeInterceptors} interceptors to finish`, { traceId: 'ON_MODULE_DESTROY' });
|
|
72
63
|
await new Promise((resolve) => {
|
|
73
|
-
setTimeout(resolve,
|
|
64
|
+
setTimeout(resolve, 100);
|
|
74
65
|
});
|
|
75
66
|
}
|
|
76
67
|
}
|
package/package.json
CHANGED
|
@@ -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;
|