@yolo-croket-dev/core 1.4.52 → 1.4.53-slowquery.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.
|
@@ -1,9 +1,11 @@
|
|
|
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 '../services';
|
|
4
5
|
export declare class RPCInterceptor implements NestInterceptor {
|
|
5
6
|
private readonly reflector;
|
|
6
|
-
|
|
7
|
+
private readonly gracefulShutdownService;
|
|
8
|
+
constructor(reflector: Reflector, gracefulShutdownService: GracefulShutdownService);
|
|
7
9
|
private maxLengthOverShorten;
|
|
8
10
|
private updateMaxLengthArrayShorten;
|
|
9
11
|
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<unknown>>;
|
|
@@ -18,11 +18,13 @@ const operators_1 = require("rxjs/operators");
|
|
|
18
18
|
// import Logger from '@yolo-croket-dev/logger';
|
|
19
19
|
const functions_1 = require("../functions");
|
|
20
20
|
const exceptions_1 = require("../exceptions");
|
|
21
|
+
const services_1 = require("../services");
|
|
21
22
|
// const MAX_CUT_LENGTH = 500;
|
|
22
23
|
const MAX_LENGTH = 300;
|
|
23
24
|
let RPCInterceptor = class RPCInterceptor {
|
|
24
|
-
constructor(reflector) {
|
|
25
|
+
constructor(reflector, gracefulShutdownService) {
|
|
25
26
|
this.reflector = reflector;
|
|
27
|
+
this.gracefulShutdownService = gracefulShutdownService;
|
|
26
28
|
}
|
|
27
29
|
maxLengthOverShorten(data) {
|
|
28
30
|
if (typeof data !== 'string') {
|
|
@@ -165,6 +167,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
165
167
|
errMessage,
|
|
166
168
|
errAction,
|
|
167
169
|
};
|
|
170
|
+
// eslint-disable-next-line max-len
|
|
168
171
|
if (!Number.isNaN(staticRetryCount) && staticRetryCount && err.isRetry !== false) { /** 재시도 로직이 필요한 경우, 0보다 커야 정의된것. 기본값이 0, isRetry값이 false로 정의된 에러가 아니라면 전부 재시도 */
|
|
169
172
|
if (reDeliveryCount <= (staticRetryCount - 1)) { /** 재시도 횟수가 있고, 재시도 횟수보다 적을 경우, 0부터 카운팅 되므로 -1 */
|
|
170
173
|
channel.nack(message, false, true);
|
|
@@ -231,6 +234,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
231
234
|
else {
|
|
232
235
|
// logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
|
|
233
236
|
}
|
|
237
|
+
this.gracefulShutdownService.incActiveInterceptors();
|
|
234
238
|
// eslint-disable-next-line consistent-return
|
|
235
239
|
return next
|
|
236
240
|
.handle()
|
|
@@ -253,11 +257,14 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
253
257
|
}
|
|
254
258
|
},
|
|
255
259
|
error: localErrorProcessor,
|
|
260
|
+
}), (0, operators_1.finalize)(() => {
|
|
261
|
+
this.gracefulShutdownService.decActiveInterceptors();
|
|
256
262
|
}));
|
|
257
263
|
}
|
|
258
264
|
};
|
|
259
265
|
exports.RPCInterceptor = RPCInterceptor;
|
|
260
266
|
exports.RPCInterceptor = RPCInterceptor = __decorate([
|
|
261
267
|
(0, common_1.Injectable)(),
|
|
262
|
-
__metadata("design:paramtypes", [core_1.Reflector
|
|
268
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
269
|
+
services_1.GracefulShutdownService])
|
|
263
270
|
], RPCInterceptor);
|
package/package.json
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
export declare class GracefulShutdownService implements OnApplicationShutdown {
|
|
3
|
+
private activeInterceptors;
|
|
4
|
+
incActiveInterceptors(): void;
|
|
5
|
+
decActiveInterceptors(): void;
|
|
6
|
+
onApplicationShutdown(signal?: string): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 = 0;
|
|
39
|
+
}
|
|
40
|
+
incActiveInterceptors() {
|
|
41
|
+
this.activeInterceptors += 1;
|
|
42
|
+
}
|
|
43
|
+
decActiveInterceptors() {
|
|
44
|
+
this.activeInterceptors -= 1;
|
|
45
|
+
}
|
|
46
|
+
async onApplicationShutdown(signal) {
|
|
47
|
+
msaLogger.debug(`GracefulShutdownService.onApplicationShutdown: ${signal}`, { traceId: 'ON_APPLICATION_SHUTDOWN' });
|
|
48
|
+
while (this.activeInterceptors > 0) {
|
|
49
|
+
await new Promise((resolve) => {
|
|
50
|
+
setTimeout(resolve, 100);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.GracefulShutdownService = GracefulShutdownService;
|
|
56
|
+
exports.GracefulShutdownService = GracefulShutdownService = __decorate([
|
|
57
|
+
(0, common_1.Injectable)()
|
|
58
|
+
], GracefulShutdownService);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './graceful-shutdown.service';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./graceful-shutdown.service"), exports);
|