@yolo-croket-dev/core 1.4.53-slowquery.12 → 1.4.53-slowquery.2
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 +6 -45
- 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 -30
- 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
|
@@ -1,33 +1,10 @@
|
|
|
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
|
};
|
|
@@ -38,13 +15,10 @@ const common_1 = require("@nestjs/common");
|
|
|
38
15
|
const core_1 = require("@nestjs/core");
|
|
39
16
|
const rxjs_1 = require("rxjs");
|
|
40
17
|
const operators_1 = require("rxjs/operators");
|
|
41
|
-
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
42
18
|
// import Logger from '@yolo-croket-dev/logger';
|
|
43
19
|
const functions_1 = require("../functions");
|
|
44
20
|
const exceptions_1 = require("../exceptions");
|
|
45
21
|
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 {
|
|
@@ -134,7 +108,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
134
108
|
// return data;
|
|
135
109
|
// }
|
|
136
110
|
async intercept(context, next) {
|
|
137
|
-
var _a
|
|
111
|
+
var _a;
|
|
138
112
|
const options = this.reflector.get('rpcInterceptorScope', context.getHandler());
|
|
139
113
|
const args = context.getArgs();
|
|
140
114
|
const arg = args[0];
|
|
@@ -146,25 +120,13 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
146
120
|
// const traceId = content.data.param ? content.data.param.traceId : null;
|
|
147
121
|
const isInternal = content.data.param ? content.data.param.isInternal : false;
|
|
148
122
|
const isAdmin = content.data.param ? content.data.param.isAdmin : false;
|
|
123
|
+
// const method = content.pattern;
|
|
149
124
|
const reDeliveryCount = Number(message.properties.headers['x-delivery-count']) || 0; /** 몇번 재전달되었는지 */
|
|
150
125
|
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
126
|
// const logParam = {
|
|
159
127
|
// traceId,
|
|
160
128
|
// method,
|
|
161
129
|
// };
|
|
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
130
|
if (!staticRetryCount && reDeliveryCount > 0) {
|
|
169
131
|
channel.sendToQueue(message.properties.replyTo, Buffer.from(JSON.stringify({
|
|
170
132
|
isError: true,
|
|
@@ -243,7 +205,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
243
205
|
};
|
|
244
206
|
localErrorProcessor = localErrorProcessor.bind(this);
|
|
245
207
|
/** 파일 객체 처리 */
|
|
246
|
-
(0, functions_1.reWriteFileValue)((
|
|
208
|
+
(0, functions_1.reWriteFileValue)((_a = content === null || content === void 0 ? void 0 : content.data) === null || _a === void 0 ? void 0 : _a.file);
|
|
247
209
|
if (options) {
|
|
248
210
|
if (options.maxLengthKeys && options.maxLengthKeys.length) {
|
|
249
211
|
for (const key of options.maxLengthKeys) {
|
|
@@ -272,12 +234,11 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
272
234
|
else {
|
|
273
235
|
// logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
|
|
274
236
|
}
|
|
275
|
-
this.gracefulShutdownService.
|
|
237
|
+
this.gracefulShutdownService.incActiveInterceptors();
|
|
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;
|
|
@@ -297,7 +258,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
297
258
|
},
|
|
298
259
|
error: localErrorProcessor,
|
|
299
260
|
}), (0, operators_1.finalize)(() => {
|
|
300
|
-
this.gracefulShutdownService.
|
|
261
|
+
this.gracefulShutdownService.decActiveInterceptors();
|
|
301
262
|
}));
|
|
302
263
|
}
|
|
303
264
|
};
|
|
@@ -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,44 +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
|
-
|
|
46
|
-
this.activeInterceptors
|
|
47
|
-
}
|
|
48
|
-
popActiveInterceptors(execInterceptor) {
|
|
49
|
-
console.log('GracefulShutdownService.popActiveInterceptors', { traceId: 'POP_ACTIVE_INTERCEPTORS' }, { execInterceptor });
|
|
50
|
-
// eslint-disable-next-line max-len
|
|
51
|
-
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' });
|
|
52
47
|
}
|
|
53
48
|
async onApplicationShutdown(signal) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
}
|
|
57
57
|
}
|
|
58
58
|
async onModuleDestroy() {
|
|
59
|
-
this.isApplicationExit = true;
|
|
60
59
|
msaLogger.debug('GracefulShutdownService.onModuleDestroy', { traceId: 'ON_MODULE_DESTROY' });
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
console.debug('GracefulShutdownService.onModuleDestroy activeInterceptors', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
65
|
-
let prevExecInterceptorCount = 0;
|
|
66
|
-
while (this.activeInterceptors.length) {
|
|
67
|
-
if (prevExecInterceptorCount !== this.activeInterceptors.length) {
|
|
68
|
-
prevExecInterceptorCount = this.activeInterceptors.length;
|
|
69
|
-
// eslint-disable-next-line max-len
|
|
70
|
-
console.log('GracefulShutdownService.onModuleDestroy: waiting for interceptors to finish', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
71
|
-
// eslint-disable-next-line max-len
|
|
72
|
-
msaLogger.debug('GracefulShutdownService.onModuleDestroy: waiting for interceptors to finish', { traceId: 'ON_MODULE_DESTROY' }, { activeInterceptors: this.activeInterceptors });
|
|
73
|
-
}
|
|
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' });
|
|
74
63
|
await new Promise((resolve) => {
|
|
75
|
-
setTimeout(resolve,
|
|
64
|
+
setTimeout(resolve, 100);
|
|
76
65
|
});
|
|
77
66
|
}
|
|
78
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;
|