@yolo-croket-dev/core 1.7.25-slowquery.12 → 1.7.25-slowquery.13
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.
|
@@ -186,7 +186,8 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
186
186
|
console.log('args: ', args);
|
|
187
187
|
console.log('context: ', context);
|
|
188
188
|
const abortablePromise = new abortable_promise_1.AbortablePromise((...args) => handler(...args), abortController.signal);
|
|
189
|
-
|
|
189
|
+
console.log('abortablePromise: ', abortablePromise);
|
|
190
|
+
// (context as any).handler = abortablePromise;
|
|
190
191
|
console.log('handler: ', handler);
|
|
191
192
|
console.log('context: ', context);
|
|
192
193
|
// const messageId = (rmq as any).messageId;
|
|
@@ -3,12 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GracefulServerRMQ = void 0;
|
|
4
4
|
const microservices_1 = require("@nestjs/microservices");
|
|
5
5
|
const node_util_1 = require("node:util");
|
|
6
|
-
const abortable_promise_1 = require("@xuchaoqian/abortable-promise");
|
|
7
6
|
const sleep = (0, node_util_1.promisify)(setTimeout);
|
|
8
7
|
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_TIMEOUT_MS = 5000;
|
|
9
8
|
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_INTERVAL_MS = 500;
|
|
10
|
-
// const RMQ_DEFAULT_MESSAGE_TIMEOUT_MS = 1000 * 60 * 29; // 29분
|
|
11
|
-
const RMQ_DEFAULT_MESSAGE_TIMEOUT_MS = 1000 * 2; // 2분
|
|
12
9
|
class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
13
10
|
constructor(options) {
|
|
14
11
|
super(options);
|
|
@@ -39,55 +36,10 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
async handleMessage(message, channel) {
|
|
42
|
-
const messageId = message.properties.messageId || message.properties.correlationId || `msg_${Date.now()}_${Math.random()}`;
|
|
43
|
-
// AbortController 생성
|
|
44
|
-
const abortController = new AbortController();
|
|
45
|
-
// 타임아웃 설정
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
console.log(`Message timeout: ${messageId}`);
|
|
48
|
-
abortController.abort(); // Abort with default reason
|
|
49
|
-
}, RMQ_DEFAULT_MESSAGE_TIMEOUT_MS);
|
|
50
|
-
console.log('timeout 설정');
|
|
51
39
|
this.runningMessages += 1;
|
|
52
|
-
|
|
53
|
-
// AbortController를 메시지에 추가
|
|
54
|
-
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-explicit-any
|
|
55
|
-
message.abortController = abortController;
|
|
56
|
-
// eslint-disable-next-line no-param-reassign
|
|
57
|
-
message.messageId = messageId;
|
|
58
|
-
// abort 상태 확인
|
|
59
|
-
if (abortController.signal.aborted) {
|
|
60
|
-
console.log(`Message already aborted: ${messageId}`);
|
|
61
|
-
this.runningMessages -= 1;
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const abortablePromise = new abortable_promise_1.AbortablePromise((resolve, reject) => {
|
|
65
|
-
try {
|
|
66
|
-
super.handleMessage(message, channel);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
reject(err);
|
|
70
|
-
}
|
|
71
|
-
}, abortController.signal);
|
|
72
|
-
abortablePromise.then((val) => {
|
|
73
|
-
console.log('handleMessage success', val);
|
|
74
|
-
}).catch((err) => {
|
|
75
|
-
console.log('handleMessage error', err);
|
|
76
|
-
throw err;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
if (error.message.includes('Message aborted')) {
|
|
81
|
-
console.log(`Message processing aborted: ${messageId}`);
|
|
82
|
-
// abort로 인한 에러는 정상적으로 처리된 것으로 간주
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
40
|
+
return super.handleMessage(message, channel).finally(() => {
|
|
89
41
|
this.runningMessages -= 1;
|
|
90
|
-
}
|
|
42
|
+
});
|
|
91
43
|
}
|
|
92
44
|
async close() {
|
|
93
45
|
this.closing = true;
|