@yolo-croket-dev/core 1.7.25-slowquery.2 → 1.7.25-slowquery.21
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/abort-context.d.ts +33 -0
- package/functions/abort-context.js +47 -0
- package/functions/abort.d.ts +53 -0
- package/functions/abort.js +200 -0
- package/functions/index.d.ts +2 -0
- package/functions/index.js +2 -0
- package/interceptors/logging-service.interceptor.js +2 -2
- package/interceptors/rpc.interceptor.d.ts +2 -0
- package/interceptors/rpc.interceptor.js +19 -85
- package/interfaces/exception.js +3 -3
- package/modules/graceful-shutdown/graceful-shutdown.module.js +2 -2
- package/modules/graceful-shutdown/graceful-shutdown.rmq.d.ts +1 -8
- package/modules/graceful-shutdown/graceful-shutdown.rmq.js +2 -86
- package/modules/graceful-shutdown/graceful-shutdown.service.js +2 -2
- package/modules/redis.module.js +2 -2
- package/package.json +1 -1
- package/pipes/rpc-validation.pipe.js +2 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* AbortSignal을 AsyncLocalStorage를 통해 전역적으로 관리하는 컨텍스트
|
|
4
|
+
*/
|
|
5
|
+
export declare class AbortContext {
|
|
6
|
+
private static asyncLocalStorage;
|
|
7
|
+
/**
|
|
8
|
+
* AbortSignal과 함께 컨텍스트를 실행
|
|
9
|
+
* @param abortSignal 중단 신호
|
|
10
|
+
* @param requestId 요청 ID (디버깅용)
|
|
11
|
+
* @param callback 실행할 콜백 함수
|
|
12
|
+
* @returns 실행 결과
|
|
13
|
+
*/
|
|
14
|
+
static run<T>(abortSignal: AbortSignal, requestId: string, callback: () => T): T;
|
|
15
|
+
/**
|
|
16
|
+
* 현재 컨텍스트의 AbortSignal을 가져옴
|
|
17
|
+
* @returns 현재 AbortSignal 또는 null
|
|
18
|
+
*/
|
|
19
|
+
static getCurrentAbortSignal(): AbortSignal | null;
|
|
20
|
+
/**
|
|
21
|
+
* 현재 컨텍스트의 요청 ID를 가져옴
|
|
22
|
+
* @returns 현재 요청 ID 또는 null
|
|
23
|
+
*/
|
|
24
|
+
static getCurrentRequestId(): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* 현재 컨텍스트 정보를 가져옴
|
|
27
|
+
* @returns 현재 컨텍스트 또는 null
|
|
28
|
+
*/
|
|
29
|
+
static getCurrentContext(): {
|
|
30
|
+
abortSignal: AbortSignal;
|
|
31
|
+
requestId: string;
|
|
32
|
+
} | null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbortContext = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
/**
|
|
6
|
+
* AbortSignal을 AsyncLocalStorage를 통해 전역적으로 관리하는 컨텍스트
|
|
7
|
+
*/
|
|
8
|
+
class AbortContext {
|
|
9
|
+
/**
|
|
10
|
+
* AbortSignal과 함께 컨텍스트를 실행
|
|
11
|
+
* @param abortSignal 중단 신호
|
|
12
|
+
* @param requestId 요청 ID (디버깅용)
|
|
13
|
+
* @param callback 실행할 콜백 함수
|
|
14
|
+
* @returns 실행 결과
|
|
15
|
+
*/
|
|
16
|
+
static run(abortSignal, requestId, callback) {
|
|
17
|
+
return this.asyncLocalStorage.run({
|
|
18
|
+
abortSignal,
|
|
19
|
+
requestId,
|
|
20
|
+
}, callback);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 현재 컨텍스트의 AbortSignal을 가져옴
|
|
24
|
+
* @returns 현재 AbortSignal 또는 null
|
|
25
|
+
*/
|
|
26
|
+
static getCurrentAbortSignal() {
|
|
27
|
+
const context = this.asyncLocalStorage.getStore();
|
|
28
|
+
return (context === null || context === void 0 ? void 0 : context.abortSignal) || null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 현재 컨텍스트의 요청 ID를 가져옴
|
|
32
|
+
* @returns 현재 요청 ID 또는 null
|
|
33
|
+
*/
|
|
34
|
+
static getCurrentRequestId() {
|
|
35
|
+
const context = this.asyncLocalStorage.getStore();
|
|
36
|
+
return (context === null || context === void 0 ? void 0 : context.requestId) || null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 현재 컨텍스트 정보를 가져옴
|
|
40
|
+
* @returns 현재 컨텍스트 또는 null
|
|
41
|
+
*/
|
|
42
|
+
static getCurrentContext() {
|
|
43
|
+
return this.asyncLocalStorage.getStore() || null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.AbortContext = AbortContext;
|
|
47
|
+
AbortContext.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/**
|
|
4
|
+
* 현재 컨텍스트의 AbortSignal을 가져오는 전역 함수
|
|
5
|
+
* @returns 현재 AbortSignal 또는 null
|
|
6
|
+
*/
|
|
7
|
+
export declare function getCurrentAbortSignal(): AbortSignal | null;
|
|
8
|
+
/**
|
|
9
|
+
* 현재 AbortSignal이 중단되었는지 확인
|
|
10
|
+
* @returns 중단 여부
|
|
11
|
+
*/
|
|
12
|
+
export declare function isAborted(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* AbortSignal이 중단되었을 때 에러를 던지는 함수
|
|
15
|
+
* @param message 에러 메시지
|
|
16
|
+
* @throws 중단된 경우 에러 발생
|
|
17
|
+
*/
|
|
18
|
+
export declare function throwIfAborted(message?: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* AbortSignal을 감지하여 중단 가능한 Promise를 생성
|
|
21
|
+
* @param promise 원본 Promise
|
|
22
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
23
|
+
* @returns 중단 가능한 Promise
|
|
24
|
+
*/
|
|
25
|
+
export declare function withAbortSignal<T>(promise: Promise<T>, abortSignal?: AbortSignal): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* AbortSignal을 감지하여 중단 가능한 delay
|
|
28
|
+
* @param ms 지연 시간 (밀리초)
|
|
29
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
30
|
+
* @returns 중단 가능한 Promise
|
|
31
|
+
*/
|
|
32
|
+
export declare function delayWithAbort(ms: number, abortSignal?: AbortSignal): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* AbortSignal을 감지하여 중단 가능한 setTimeout
|
|
35
|
+
* @param callback 실행할 콜백 함수
|
|
36
|
+
* @param delay 지연 시간 (밀리초)
|
|
37
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
38
|
+
* @returns 타이머 ID
|
|
39
|
+
*/
|
|
40
|
+
export declare function setTimeoutWithAbort(callback: () => void, delay: number, abortSignal?: AbortSignal): NodeJS.Timeout;
|
|
41
|
+
/**
|
|
42
|
+
* AbortSignal을 감지하여 중단 가능한 반복 작업
|
|
43
|
+
* @param task 반복할 작업 함수
|
|
44
|
+
* @param interval 반복 간격 (밀리초)
|
|
45
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
46
|
+
* @returns 중단 가능한 Promise
|
|
47
|
+
*/
|
|
48
|
+
export declare function repeatWithAbort(task: () => Promise<void> | void, interval: number, abortSignal?: AbortSignal): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* 현재 컨텍스트 정보를 로깅하는 디버그 함수
|
|
51
|
+
* @param message 로그 메시지
|
|
52
|
+
*/
|
|
53
|
+
export declare function logAbortContext(message: string): void;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logAbortContext = exports.repeatWithAbort = exports.setTimeoutWithAbort = exports.delayWithAbort = exports.withAbortSignal = exports.throwIfAborted = exports.isAborted = exports.getCurrentAbortSignal = void 0;
|
|
4
|
+
const abort_context_1 = require("./abort-context");
|
|
5
|
+
/**
|
|
6
|
+
* 현재 컨텍스트의 AbortSignal을 가져오는 전역 함수
|
|
7
|
+
* @returns 현재 AbortSignal 또는 null
|
|
8
|
+
*/
|
|
9
|
+
function getCurrentAbortSignal() {
|
|
10
|
+
return abort_context_1.AbortContext.getCurrentAbortSignal();
|
|
11
|
+
}
|
|
12
|
+
exports.getCurrentAbortSignal = getCurrentAbortSignal;
|
|
13
|
+
/**
|
|
14
|
+
* 현재 AbortSignal이 중단되었는지 확인
|
|
15
|
+
* @returns 중단 여부
|
|
16
|
+
*/
|
|
17
|
+
function isAborted() {
|
|
18
|
+
var _a;
|
|
19
|
+
const signal = getCurrentAbortSignal();
|
|
20
|
+
return (_a = signal === null || signal === void 0 ? void 0 : signal.aborted) !== null && _a !== void 0 ? _a : false;
|
|
21
|
+
}
|
|
22
|
+
exports.isAborted = isAborted;
|
|
23
|
+
/**
|
|
24
|
+
* AbortSignal이 중단되었을 때 에러를 던지는 함수
|
|
25
|
+
* @param message 에러 메시지
|
|
26
|
+
* @throws 중단된 경우 에러 발생
|
|
27
|
+
*/
|
|
28
|
+
function throwIfAborted(message = '작업이 중단되었습니다') {
|
|
29
|
+
if (isAborted()) {
|
|
30
|
+
throw new Error(`REQUEST_ABORTED: ${message}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.throwIfAborted = throwIfAborted;
|
|
34
|
+
/**
|
|
35
|
+
* AbortSignal을 감지하여 중단 가능한 Promise를 생성
|
|
36
|
+
* @param promise 원본 Promise
|
|
37
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
38
|
+
* @returns 중단 가능한 Promise
|
|
39
|
+
*/
|
|
40
|
+
function withAbortSignal(promise, abortSignal) {
|
|
41
|
+
const signal = abortSignal || getCurrentAbortSignal();
|
|
42
|
+
if (!signal) {
|
|
43
|
+
return promise;
|
|
44
|
+
}
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
// 이미 중단된 경우
|
|
47
|
+
if (signal.aborted) {
|
|
48
|
+
reject(new Error('REQUEST_ABORTED: 작업이 이미 중단되었습니다'));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// 중단 이벤트 리스너 등록
|
|
52
|
+
const abortHandler = () => {
|
|
53
|
+
reject(new Error('REQUEST_ABORTED: 작업이 중단되었습니다'));
|
|
54
|
+
};
|
|
55
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
56
|
+
// 원본 Promise 처리
|
|
57
|
+
promise
|
|
58
|
+
.then((result) => {
|
|
59
|
+
signal.removeEventListener('abort', abortHandler);
|
|
60
|
+
resolve(result);
|
|
61
|
+
})
|
|
62
|
+
.catch((error) => {
|
|
63
|
+
signal.removeEventListener('abort', abortHandler);
|
|
64
|
+
reject(error);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.withAbortSignal = withAbortSignal;
|
|
69
|
+
/**
|
|
70
|
+
* AbortSignal을 감지하여 중단 가능한 delay
|
|
71
|
+
* @param ms 지연 시간 (밀리초)
|
|
72
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
73
|
+
* @returns 중단 가능한 Promise
|
|
74
|
+
*/
|
|
75
|
+
function delayWithAbort(ms, abortSignal) {
|
|
76
|
+
const signal = abortSignal || getCurrentAbortSignal();
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
if (!signal) {
|
|
79
|
+
setTimeout(resolve, ms);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// 이미 중단된 경우
|
|
83
|
+
if (signal.aborted) {
|
|
84
|
+
reject(new Error('REQUEST_ABORTED: 작업이 이미 중단되었습니다'));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const timerId = setTimeout(() => {
|
|
88
|
+
if (!signal.aborted) {
|
|
89
|
+
resolve();
|
|
90
|
+
}
|
|
91
|
+
}, ms);
|
|
92
|
+
// 중단 이벤트 리스너 등록
|
|
93
|
+
const abortHandler = () => {
|
|
94
|
+
clearTimeout(timerId);
|
|
95
|
+
reject(new Error('REQUEST_ABORTED: 작업이 중단되었습니다'));
|
|
96
|
+
};
|
|
97
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.delayWithAbort = delayWithAbort;
|
|
101
|
+
/**
|
|
102
|
+
* AbortSignal을 감지하여 중단 가능한 setTimeout
|
|
103
|
+
* @param callback 실행할 콜백 함수
|
|
104
|
+
* @param delay 지연 시간 (밀리초)
|
|
105
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
106
|
+
* @returns 타이머 ID
|
|
107
|
+
*/
|
|
108
|
+
function setTimeoutWithAbort(callback, delay, abortSignal) {
|
|
109
|
+
const signal = abortSignal || getCurrentAbortSignal();
|
|
110
|
+
if (!signal) {
|
|
111
|
+
return setTimeout(callback, delay);
|
|
112
|
+
}
|
|
113
|
+
// 이미 중단된 경우
|
|
114
|
+
if (signal.aborted) {
|
|
115
|
+
throw new Error('REQUEST_ABORTED: 작업이 이미 중단되었습니다');
|
|
116
|
+
}
|
|
117
|
+
const timerId = setTimeout(() => {
|
|
118
|
+
if (!signal.aborted) {
|
|
119
|
+
callback();
|
|
120
|
+
}
|
|
121
|
+
}, delay);
|
|
122
|
+
// 중단 이벤트 리스너 등록
|
|
123
|
+
const abortHandler = () => {
|
|
124
|
+
clearTimeout(timerId);
|
|
125
|
+
};
|
|
126
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
127
|
+
return timerId;
|
|
128
|
+
}
|
|
129
|
+
exports.setTimeoutWithAbort = setTimeoutWithAbort;
|
|
130
|
+
/**
|
|
131
|
+
* AbortSignal을 감지하여 중단 가능한 반복 작업
|
|
132
|
+
* @param task 반복할 작업 함수
|
|
133
|
+
* @param interval 반복 간격 (밀리초)
|
|
134
|
+
* @param abortSignal 중단 신호 (선택사항, 없으면 현재 컨텍스트에서 가져옴)
|
|
135
|
+
* @returns 중단 가능한 Promise
|
|
136
|
+
*/
|
|
137
|
+
function repeatWithAbort(task, interval, abortSignal) {
|
|
138
|
+
const signal = abortSignal || getCurrentAbortSignal();
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
if (!signal) {
|
|
141
|
+
// abortSignal이 없으면 일반적인 반복 실행
|
|
142
|
+
const runTask = async () => {
|
|
143
|
+
try {
|
|
144
|
+
await task();
|
|
145
|
+
setTimeout(runTask, interval);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
reject(error);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
runTask();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// 이미 중단된 경우
|
|
155
|
+
if (signal.aborted) {
|
|
156
|
+
reject(new Error('REQUEST_ABORTED: 작업이 이미 중단되었습니다'));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const runTask = async () => {
|
|
160
|
+
if (signal.aborted) {
|
|
161
|
+
reject(new Error('REQUEST_ABORTED: 작업이 중단되었습니다'));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
await task();
|
|
166
|
+
if (!signal.aborted) {
|
|
167
|
+
setTimeout(runTask, interval);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
reject(new Error('REQUEST_ABORTED: 작업이 중단되었습니다'));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
reject(error);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
// 중단 이벤트 리스너 등록
|
|
178
|
+
const abortHandler = () => {
|
|
179
|
+
reject(new Error('REQUEST_ABORTED: 작업이 중단되었습니다'));
|
|
180
|
+
};
|
|
181
|
+
signal.addEventListener('abort', abortHandler, { once: true });
|
|
182
|
+
runTask();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
exports.repeatWithAbort = repeatWithAbort;
|
|
186
|
+
/**
|
|
187
|
+
* 현재 컨텍스트 정보를 로깅하는 디버그 함수
|
|
188
|
+
* @param message 로그 메시지
|
|
189
|
+
*/
|
|
190
|
+
function logAbortContext(message) {
|
|
191
|
+
var _a;
|
|
192
|
+
const context = abort_context_1.AbortContext.getCurrentContext();
|
|
193
|
+
// eslint-disable-next-line no-console
|
|
194
|
+
console.log(`[AbortContext] ${message}`, {
|
|
195
|
+
requestId: context === null || context === void 0 ? void 0 : context.requestId,
|
|
196
|
+
isAborted: (_a = context === null || context === void 0 ? void 0 : context.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted,
|
|
197
|
+
hasSignal: !!(context === null || context === void 0 ? void 0 : context.abortSignal),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
exports.logAbortContext = logAbortContext;
|
package/functions/index.d.ts
CHANGED
package/functions/index.js
CHANGED
|
@@ -20,3 +20,5 @@ __exportStar(require("./amqp-publish.function"), exports);
|
|
|
20
20
|
__exportStar(require("./rewrite-file-value.function"), exports);
|
|
21
21
|
__exportStar(require("./amqp-call-manager.function"), exports);
|
|
22
22
|
__exportStar(require("./extract-redis-url.function"), exports);
|
|
23
|
+
__exportStar(require("./abort"), exports);
|
|
24
|
+
__exportStar(require("./abort-context"), exports);
|
|
@@ -188,7 +188,7 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
188
188
|
}));
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
|
-
LoggingServiceInterceptor =
|
|
191
|
+
exports.LoggingServiceInterceptor = LoggingServiceInterceptor;
|
|
192
|
+
exports.LoggingServiceInterceptor = LoggingServiceInterceptor = __decorate([
|
|
192
193
|
(0, common_1.Injectable)()
|
|
193
194
|
], LoggingServiceInterceptor);
|
|
194
|
-
exports.LoggingServiceInterceptor = LoggingServiceInterceptor;
|
|
@@ -5,6 +5,8 @@ import { GracefulShutdownService } from '../modules/graceful-shutdown/graceful-s
|
|
|
5
5
|
export declare class RPCInterceptor implements NestInterceptor {
|
|
6
6
|
private readonly reflector;
|
|
7
7
|
private readonly gracefulShutdownService;
|
|
8
|
+
protected readonly DEFAULT_TIMEOUT = 1000;
|
|
9
|
+
protected readonly DEFAULT_TIMEOUT_MESSAGE = "\uC694\uCCAD\uC774 \uD0C0\uC784\uC544\uC6C3\uB418\uC5C8\uC2B5\uB2C8\uB2E4.";
|
|
8
10
|
constructor(reflector: Reflector, gracefulShutdownService: GracefulShutdownService);
|
|
9
11
|
private maxLengthOverShorten;
|
|
10
12
|
/** 메시지가 재전송되었을때에, 재시도 Count가 명시되어 있지 않을때에 처리 할지 여부를 결정하는 함수 */
|
|
@@ -44,11 +44,9 @@ const rxjs_1 = require("rxjs");
|
|
|
44
44
|
const operators_1 = require("rxjs/operators");
|
|
45
45
|
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
46
46
|
const amqplib_1 = __importDefault(require("amqplib"));
|
|
47
|
-
// import Logger from '@yolo-croket-dev/logger';
|
|
48
47
|
const functions_1 = require("../functions");
|
|
49
48
|
const exceptions_1 = require("../exceptions");
|
|
50
49
|
const graceful_shutdown_service_1 = require("../modules/graceful-shutdown/graceful-shutdown.service");
|
|
51
|
-
// const logger = Logger.createLogger('RPCInterceptor');
|
|
52
50
|
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
53
51
|
// const MAX_CUT_LENGTH = 500;
|
|
54
52
|
const MAX_LENGTH = 300;
|
|
@@ -56,6 +54,9 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
56
54
|
constructor(reflector, gracefulShutdownService) {
|
|
57
55
|
this.reflector = reflector;
|
|
58
56
|
this.gracefulShutdownService = gracefulShutdownService;
|
|
57
|
+
this.DEFAULT_TIMEOUT = 1000; // 29분 타임아웃
|
|
58
|
+
// protected readonly DEFAULT_TIMEOUT = 1000 * 60 * 29; // 29분 타임아웃
|
|
59
|
+
this.DEFAULT_TIMEOUT_MESSAGE = '요청이 타임아웃되었습니다.';
|
|
59
60
|
}
|
|
60
61
|
maxLengthOverShorten(data) {
|
|
61
62
|
if (typeof data !== 'string') {
|
|
@@ -146,48 +147,12 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
146
147
|
}
|
|
147
148
|
return obj;
|
|
148
149
|
}
|
|
149
|
-
// private keyCutter(data: string) {
|
|
150
|
-
// try {
|
|
151
|
-
// if (data) {
|
|
152
|
-
// data = JSON.parse(data);
|
|
153
|
-
// } else {
|
|
154
|
-
// return data;
|
|
155
|
-
// }
|
|
156
|
-
// } catch (err) {
|
|
157
|
-
// return data;
|
|
158
|
-
// }
|
|
159
|
-
// for (const key of Object.keys(data)) {
|
|
160
|
-
// const type = typeof data[key as any];
|
|
161
|
-
// if (type === 'string') {
|
|
162
|
-
// if (data[key as any].length > MAX_CUT_LENGTH) {
|
|
163
|
-
// (data[key as any] as any) = `${data[key as any].slice(0, MAX_CUT_LENGTH)}...`;
|
|
164
|
-
// }
|
|
165
|
-
// } else if (type === 'object') {
|
|
166
|
-
// if (data[key as any] === null) {
|
|
167
|
-
// (data[key as any] as any) = null;
|
|
168
|
-
// } else {
|
|
169
|
-
// (data[key as any] as any) = this.keyCutter(data[key as any]);
|
|
170
|
-
// }
|
|
171
|
-
// }
|
|
172
|
-
// }
|
|
173
|
-
// return data;
|
|
174
|
-
// }
|
|
175
150
|
async intercept(context, next) {
|
|
176
151
|
var _a, _b, _c, _d, _e;
|
|
177
152
|
const options = this.reflector.get('rpcInterceptorScope', context.getHandler());
|
|
178
153
|
const args = context.getArgs();
|
|
179
154
|
const arg = args[0];
|
|
180
155
|
const rmq = args[1];
|
|
181
|
-
// 메시지에서 AbortController 가져오기
|
|
182
|
-
const abortController = rmq.args[0].abortController;
|
|
183
|
-
// const messageId = (rmq as any).messageId;
|
|
184
|
-
// if (!abortController) {
|
|
185
|
-
// // AbortController가 없으면 기본 처리
|
|
186
|
-
// return next.handle().pipe(
|
|
187
|
-
// timeout(1000 * 60 * 29),
|
|
188
|
-
// // ... 기존 로직
|
|
189
|
-
// );
|
|
190
|
-
// }
|
|
191
156
|
const channel = rmq.getChannelRef();
|
|
192
157
|
const message = rmq.getMessage();
|
|
193
158
|
const now = Date.now();
|
|
@@ -204,6 +169,7 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
204
169
|
correlationId,
|
|
205
170
|
isMessageAck: false,
|
|
206
171
|
};
|
|
172
|
+
const abortController = new AbortController();
|
|
207
173
|
/** consume 메시지 전부 cancel */
|
|
208
174
|
if (this.gracefulShutdownService.isApplicationExit) {
|
|
209
175
|
msaLogger.debug('RPCInterceptor isApplicationExit called', { traceId: 'IS_APPLICATION_EXIT' });
|
|
@@ -264,13 +230,6 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
264
230
|
errMessage,
|
|
265
231
|
errAction,
|
|
266
232
|
};
|
|
267
|
-
// const isTimeoutError = err instanceof Error && err.name === 'TimeoutError';
|
|
268
|
-
// if (isTimeoutError) {
|
|
269
|
-
// channel.nack(message, false, true);
|
|
270
|
-
// message.properties.replyTo = undefined; /** replyTo가 존재하면 sendToQueue가 호출되므로, 삭제해주기 */
|
|
271
|
-
// execInterceptor.isMessageAck = true;
|
|
272
|
-
// return EMPTY;
|
|
273
|
-
// }
|
|
274
233
|
if (!Number.isNaN(staticRetryCount)
|
|
275
234
|
&& staticRetryCount
|
|
276
235
|
&& err.isRetry !== false) {
|
|
@@ -303,11 +262,6 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
303
262
|
const messageContent = message.content.toString();
|
|
304
263
|
/** 파일 객체 처리 */
|
|
305
264
|
(0, functions_1.reWriteFileValue)((_a = messageContent === null || messageContent === void 0 ? void 0 : messageContent.data) === null || _a === void 0 ? void 0 : _a.file);
|
|
306
|
-
// logger.debug(`<= (error:${traceId}): ${JSON.stringify(sendMessage.toString())}`, {
|
|
307
|
-
// ...logParam,
|
|
308
|
-
// duration,
|
|
309
|
-
// isError: true,
|
|
310
|
-
// });
|
|
311
265
|
if (!noAck && !isAck) {
|
|
312
266
|
channel.ack(message);
|
|
313
267
|
execInterceptor.isMessageAck = true;
|
|
@@ -336,36 +290,19 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
336
290
|
return new rxjs_1.Observable();
|
|
337
291
|
}
|
|
338
292
|
}
|
|
339
|
-
if (content.pattern === 'UPLOAD_FILE') {
|
|
340
|
-
if (content.data.payload.file) {
|
|
341
|
-
content.data.payload.file = `${content.data.payload.file.slice(0, 30)}...`;
|
|
342
|
-
}
|
|
343
|
-
// logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
// logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
|
|
347
|
-
}
|
|
348
293
|
this.gracefulShutdownService.pushActiveInterceptors(execInterceptor);
|
|
349
294
|
// eslint-disable-next-line consistent-return
|
|
350
|
-
return next
|
|
295
|
+
return functions_1.AbortContext.run(abortController.signal, execInterceptor.traceId, () => next
|
|
351
296
|
.handle()
|
|
352
|
-
.pipe(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// 정리 함수
|
|
362
|
-
return () => {
|
|
363
|
-
abortController.signal.removeEventListener('abort', abortHandler);
|
|
364
|
-
};
|
|
365
|
-
})),
|
|
366
|
-
// timeout(1000 * 60 * 29), // 30분 타임아웃
|
|
367
|
-
(0, operators_1.timeout)(1000 * 30), // 30분 타임아웃
|
|
368
|
-
(0, operators_1.tap)({
|
|
297
|
+
.pipe((0, operators_1.timeout)({
|
|
298
|
+
each: this.DEFAULT_TIMEOUT,
|
|
299
|
+
with: () => {
|
|
300
|
+
console.log('RPCInterceptor timeout 발생');
|
|
301
|
+
msaLogger.error('RPCInterceptor timeout 발생', { traceId: execInterceptor.traceId }, { message: this.DEFAULT_TIMEOUT_MESSAGE });
|
|
302
|
+
abortController.abort();
|
|
303
|
+
return (0, rxjs_1.throwError)(() => new Error(this.DEFAULT_TIMEOUT_MESSAGE));
|
|
304
|
+
},
|
|
305
|
+
}), (0, operators_1.tap)({
|
|
369
306
|
next: async (val) => {
|
|
370
307
|
val.isError = false;
|
|
371
308
|
// const duration = Date.now() - now;
|
|
@@ -390,12 +327,9 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
390
327
|
// eslint-disable-next-line consistent-return
|
|
391
328
|
(0, operators_1.catchError)(async (err) => {
|
|
392
329
|
// timeout 에러 처리
|
|
393
|
-
|
|
330
|
+
console.log('RPCInterceptor catchError 발생', err);
|
|
331
|
+
const isTimeoutError = err instanceof Error && (err.name === 'TimeoutError' || err.message === this.DEFAULT_TIMEOUT_MESSAGE);
|
|
394
332
|
if (isTimeoutError) {
|
|
395
|
-
if (abortController) {
|
|
396
|
-
abortController.abort();
|
|
397
|
-
throw new Error('Message aborted due to timeout');
|
|
398
|
-
}
|
|
399
333
|
msaLogger.error('[타임 아웃] 메시지 재전송 처리', { traceId: execInterceptor.traceId }, {
|
|
400
334
|
error: {
|
|
401
335
|
message: err.message,
|
|
@@ -425,12 +359,12 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
425
359
|
}
|
|
426
360
|
}), (0, operators_1.finalize)(() => {
|
|
427
361
|
this.gracefulShutdownService.popActiveInterceptors(execInterceptor);
|
|
428
|
-
}));
|
|
362
|
+
})));
|
|
429
363
|
}
|
|
430
364
|
};
|
|
431
|
-
RPCInterceptor =
|
|
365
|
+
exports.RPCInterceptor = RPCInterceptor;
|
|
366
|
+
exports.RPCInterceptor = RPCInterceptor = __decorate([
|
|
432
367
|
(0, common_1.Injectable)(),
|
|
433
368
|
__metadata("design:paramtypes", [core_1.Reflector,
|
|
434
369
|
graceful_shutdown_service_1.GracefulShutdownService])
|
|
435
370
|
], RPCInterceptor);
|
|
436
|
-
exports.RPCInterceptor = RPCInterceptor;
|
package/interfaces/exception.js
CHANGED
|
@@ -18,9 +18,10 @@ var ErrActionTypeEnum;
|
|
|
18
18
|
ErrActionTypeEnum["LEGACY_SHOW_TOAST"] = "LEGACY_SHOW_TOAST";
|
|
19
19
|
ErrActionTypeEnum["FORCE_UPDATE"] = "FORCE_UPDATE";
|
|
20
20
|
ErrActionTypeEnum["UPDATE_ACCESS_TOKEN"] = "UPDATE_ACCESS_TOKEN";
|
|
21
|
-
})(ErrActionTypeEnum
|
|
21
|
+
})(ErrActionTypeEnum || (exports.ErrActionTypeEnum = ErrActionTypeEnum = {}));
|
|
22
22
|
class ErrAction {
|
|
23
23
|
}
|
|
24
|
+
exports.ErrAction = ErrAction;
|
|
24
25
|
__decorate([
|
|
25
26
|
(0, swagger_1.ApiProperty)({
|
|
26
27
|
description: '액션 타입',
|
|
@@ -57,9 +58,9 @@ __decorate([
|
|
|
57
58
|
}),
|
|
58
59
|
__metadata("design:type", String)
|
|
59
60
|
], ErrAction.prototype, "webViewUrl", void 0);
|
|
60
|
-
exports.ErrAction = ErrAction;
|
|
61
61
|
class ErrInfo {
|
|
62
62
|
}
|
|
63
|
+
exports.ErrInfo = ErrInfo;
|
|
63
64
|
__decorate([
|
|
64
65
|
(0, swagger_1.ApiProperty)({
|
|
65
66
|
description: '에러 종류 식별자',
|
|
@@ -81,4 +82,3 @@ __decorate([
|
|
|
81
82
|
}),
|
|
82
83
|
__metadata("design:type", ErrAction)
|
|
83
84
|
], ErrInfo.prototype, "action", void 0);
|
|
84
|
-
exports.ErrInfo = ErrInfo;
|
|
@@ -25,7 +25,8 @@ let GracefulShutdownModule = class GracefulShutdownModule {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
GracefulShutdownModule =
|
|
28
|
+
exports.GracefulShutdownModule = GracefulShutdownModule;
|
|
29
|
+
exports.GracefulShutdownModule = GracefulShutdownModule = __decorate([
|
|
29
30
|
(0, common_1.Global)(),
|
|
30
31
|
(0, common_1.Module)({
|
|
31
32
|
providers: [graceful_shutdown_service_1.GracefulShutdownService],
|
|
@@ -33,4 +34,3 @@ GracefulShutdownModule = __decorate([
|
|
|
33
34
|
}),
|
|
34
35
|
__metadata("design:paramtypes", [graceful_shutdown_service_1.GracefulShutdownService])
|
|
35
36
|
], GracefulShutdownModule);
|
|
36
|
-
exports.GracefulShutdownModule = GracefulShutdownModule;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { RmqOptions, ServerRMQ } from '@nestjs/microservices';
|
|
4
2
|
import { Channel } from 'amqp-connection-manager';
|
|
5
3
|
import { ConsumeMessage } from 'amqplib';
|
|
6
|
-
export
|
|
4
|
+
export type GracefulRmqOptions = RmqOptions['options'] & {
|
|
7
5
|
waitingEndingHandlersTimeoutMs?: number;
|
|
8
6
|
waitingEndingHandlersIntervalMs?: number;
|
|
9
7
|
};
|
|
@@ -14,14 +12,9 @@ export declare class GracefulServerRMQ extends ServerRMQ {
|
|
|
14
12
|
protected consumerTag: string | null;
|
|
15
13
|
protected readonly waitingEndingHandlersTimeoutMs: number;
|
|
16
14
|
protected readonly waitingEndingHandlersIntervalMs: number;
|
|
17
|
-
protected messageAbortControllers: Map<string, AbortController>;
|
|
18
|
-
protected messageTimeouts: Map<string, NodeJS.Timeout>;
|
|
19
15
|
constructor(options: GracefulRmqOptions);
|
|
20
16
|
setupChannel(channel: Channel, callback: () => void): Promise<void>;
|
|
21
17
|
protected waitingHandlers(): Promise<void>;
|
|
22
18
|
handleMessage(message: ConsumeMessage, channel: Channel): Promise<void>;
|
|
23
|
-
private cleanupMessage;
|
|
24
|
-
abortMessage(messageId: string): void;
|
|
25
|
-
abortAllMessages(): void;
|
|
26
19
|
close(): Promise<void>;
|
|
27
20
|
}
|
|
@@ -6,8 +6,6 @@ const node_util_1 = require("node:util");
|
|
|
6
6
|
const sleep = (0, node_util_1.promisify)(setTimeout);
|
|
7
7
|
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_TIMEOUT_MS = 5000;
|
|
8
8
|
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_INTERVAL_MS = 500;
|
|
9
|
-
// const RMQ_DEFAULT_MESSAGE_TIMEOUT_MS = 1000 * 60 * 29; // 29분
|
|
10
|
-
const RMQ_DEFAULT_MESSAGE_TIMEOUT_MS = 1000 * 2; // 2분
|
|
11
9
|
class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
12
10
|
constructor(options) {
|
|
13
11
|
super(options);
|
|
@@ -15,10 +13,6 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
15
13
|
this.runningMessages = 0;
|
|
16
14
|
this.closing = false;
|
|
17
15
|
this.consumerTag = null;
|
|
18
|
-
// 메시지별 AbortController 관리
|
|
19
|
-
this.messageAbortControllers = new Map();
|
|
20
|
-
// eslint-disable-next-line no-undef
|
|
21
|
-
this.messageTimeouts = new Map();
|
|
22
16
|
this.waitingEndingHandlersTimeoutMs = this.getOptionsProp(this.options, 'waitingEndingHandlersTimeoutMs')
|
|
23
17
|
|| RMQ_DEFAULT_WAITING_ENDING_HANDLERS_TIMEOUT_MS;
|
|
24
18
|
this.waitingEndingHandlersIntervalMs = this.getOptionsProp(this.options, 'waitingEndingHandlersIntervalMs')
|
|
@@ -42,91 +36,13 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
38
|
async handleMessage(message, channel) {
|
|
45
|
-
const messageId = message.properties.messageId || message.properties.correlationId || `msg_${Date.now()}_${Math.random()}`;
|
|
46
|
-
// AbortController 생성
|
|
47
|
-
const abortController = new AbortController();
|
|
48
|
-
this.messageAbortControllers.set(messageId, abortController);
|
|
49
|
-
// 타임아웃 설정
|
|
50
|
-
const timeoutId = setTimeout(() => {
|
|
51
|
-
console.log(`Message timeout: ${messageId}`);
|
|
52
|
-
abortController.abort();
|
|
53
|
-
this.cleanupMessage(messageId);
|
|
54
|
-
}, RMQ_DEFAULT_MESSAGE_TIMEOUT_MS);
|
|
55
|
-
this.messageTimeouts.set(messageId, timeoutId);
|
|
56
39
|
this.runningMessages += 1;
|
|
57
|
-
|
|
58
|
-
// AbortController를 메시지에 추가
|
|
59
|
-
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
|
60
|
-
message.abortController = abortController;
|
|
61
|
-
// eslint-disable-next-line no-param-reassign
|
|
62
|
-
message.messageId = messageId;
|
|
63
|
-
// abort 상태 확인
|
|
64
|
-
if (abortController.signal.aborted) {
|
|
65
|
-
console.log(`Message already aborted: ${messageId}`);
|
|
66
|
-
this.cleanupMessage(messageId);
|
|
67
|
-
this.runningMessages -= 1;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
// Promise.race를 사용하여 abort와 handleMessage 경쟁
|
|
71
|
-
const handleMessagePromise = super.handleMessage(message, channel);
|
|
72
|
-
const abortPromise = new Promise((_, reject) => {
|
|
73
|
-
// 1초마다 abort 상태를 확인
|
|
74
|
-
const interval = setInterval(() => {
|
|
75
|
-
if (abortController.signal.aborted) {
|
|
76
|
-
reject(new Error(`Message aborted: ${messageId}`));
|
|
77
|
-
clearInterval(interval);
|
|
78
|
-
}
|
|
79
|
-
}, 1000);
|
|
80
|
-
});
|
|
81
|
-
// 둘 중 하나가 먼저 완료되면 그 결과를 반환
|
|
82
|
-
await Promise.race([
|
|
83
|
-
handleMessagePromise,
|
|
84
|
-
abortPromise,
|
|
85
|
-
]);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
if (error.message.includes('Message aborted')) {
|
|
89
|
-
console.log(`Message processing aborted: ${messageId}`);
|
|
90
|
-
// abort로 인한 에러는 정상적으로 처리된 것으로 간주
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
finally {
|
|
97
|
-
this.cleanupMessage(messageId);
|
|
40
|
+
return super.handleMessage(message, channel).finally(() => {
|
|
98
41
|
this.runningMessages -= 1;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
cleanupMessage(messageId) {
|
|
102
|
-
// 타임아웃 정리
|
|
103
|
-
const timeoutId = this.messageTimeouts.get(messageId);
|
|
104
|
-
if (timeoutId) {
|
|
105
|
-
clearTimeout(timeoutId);
|
|
106
|
-
this.messageTimeouts.delete(messageId);
|
|
107
|
-
}
|
|
108
|
-
// AbortController 정리
|
|
109
|
-
this.messageAbortControllers.delete(messageId);
|
|
110
|
-
}
|
|
111
|
-
// 특정 메시지 강제 중단
|
|
112
|
-
abortMessage(messageId) {
|
|
113
|
-
const abortController = this.messageAbortControllers.get(messageId);
|
|
114
|
-
if (abortController) {
|
|
115
|
-
abortController.abort();
|
|
116
|
-
this.cleanupMessage(messageId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// 모든 실행 중인 메시지 중단
|
|
120
|
-
abortAllMessages() {
|
|
121
|
-
for (const [messageId, abortController,] of this.messageAbortControllers) {
|
|
122
|
-
abortController.abort();
|
|
123
|
-
this.cleanupMessage(messageId);
|
|
124
|
-
}
|
|
42
|
+
});
|
|
125
43
|
}
|
|
126
44
|
async close() {
|
|
127
45
|
this.closing = true;
|
|
128
|
-
// 모든 실행 중인 메시지 중단
|
|
129
|
-
this.abortAllMessages();
|
|
130
46
|
if (this.channel) {
|
|
131
47
|
await this.channel.removeSetup(undefined, (channel) => channel.cancel(this.consumerTag));
|
|
132
48
|
}
|
|
@@ -137,7 +137,7 @@ let GracefulShutdownService = class GracefulShutdownService {
|
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
|
-
GracefulShutdownService =
|
|
140
|
+
exports.GracefulShutdownService = GracefulShutdownService;
|
|
141
|
+
exports.GracefulShutdownService = GracefulShutdownService = __decorate([
|
|
141
142
|
(0, common_1.Injectable)()
|
|
142
143
|
], GracefulShutdownService);
|
|
143
|
-
exports.GracefulShutdownService = GracefulShutdownService;
|
package/modules/redis.module.js
CHANGED
|
@@ -15,10 +15,10 @@ const redisProvider = {
|
|
|
15
15
|
};
|
|
16
16
|
let RedisModule = class RedisModule {
|
|
17
17
|
};
|
|
18
|
-
RedisModule =
|
|
18
|
+
exports.RedisModule = RedisModule;
|
|
19
|
+
exports.RedisModule = RedisModule = __decorate([
|
|
19
20
|
(0, common_1.Module)({
|
|
20
21
|
providers: [redisProvider],
|
|
21
22
|
exports: [redisProvider],
|
|
22
23
|
})
|
|
23
24
|
], RedisModule);
|
|
24
|
-
exports.RedisModule = RedisModule;
|
package/package.json
CHANGED
|
@@ -31,8 +31,8 @@ let ValidationPipe = class ValidationPipe {
|
|
|
31
31
|
return value;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
ValidationPipe =
|
|
34
|
+
exports.ValidationPipe = ValidationPipe;
|
|
35
|
+
exports.ValidationPipe = ValidationPipe = __decorate([
|
|
35
36
|
(0, common_1.Injectable)(),
|
|
36
37
|
__metadata("design:paramtypes", [Object])
|
|
37
38
|
], ValidationPipe);
|
|
38
|
-
exports.ValidationPipe = ValidationPipe;
|