@yolo-croket-dev/core 1.7.25-slowquery.4 → 1.7.25-slowquery.5
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.
|
@@ -3,6 +3,7 @@ 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");
|
|
6
7
|
const sleep = (0, node_util_1.promisify)(setTimeout);
|
|
7
8
|
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_TIMEOUT_MS = 5000;
|
|
8
9
|
const RMQ_DEFAULT_WAITING_ENDING_HANDLERS_INTERVAL_MS = 500;
|
|
@@ -44,7 +45,7 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
44
45
|
// 타임아웃 설정
|
|
45
46
|
setTimeout(() => {
|
|
46
47
|
console.log(`Message timeout: ${messageId}`);
|
|
47
|
-
abortController.abort();
|
|
48
|
+
abortController.abort(); // Abort with default reason
|
|
48
49
|
}, RMQ_DEFAULT_MESSAGE_TIMEOUT_MS);
|
|
49
50
|
console.log('timeout 설정');
|
|
50
51
|
this.runningMessages += 1;
|
|
@@ -60,8 +61,14 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
60
61
|
this.runningMessages -= 1;
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
const abortablePromise = new abortable_promise_1.AbortablePromise((resolve, reject) => {
|
|
65
|
+
super.handleMessage(message, channel).then((val) => {
|
|
66
|
+
resolve(val);
|
|
67
|
+
}).catch((err) => {
|
|
68
|
+
reject(err);
|
|
69
|
+
});
|
|
70
|
+
}, abortController.signal);
|
|
71
|
+
await abortablePromise;
|
|
65
72
|
}
|
|
66
73
|
catch (error) {
|
|
67
74
|
if (error.message.includes('Message aborted')) {
|
|
@@ -90,58 +97,5 @@ class GracefulServerRMQ extends microservices_1.ServerRMQ {
|
|
|
90
97
|
this.runningMessages = 0;
|
|
91
98
|
super.close();
|
|
92
99
|
}
|
|
93
|
-
// Promise.withResolvers를 사용한 abort signal 감지
|
|
94
|
-
async executeWithAbortSignal(task, abortController) {
|
|
95
|
-
// Promise.withResolvers 사용
|
|
96
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
97
|
-
let isAborted = false;
|
|
98
|
-
let isResolved = false;
|
|
99
|
-
// eslint-disable-next-line no-undef
|
|
100
|
-
let checkInterval = null;
|
|
101
|
-
// Abort 이벤트 리스너
|
|
102
|
-
const abortHandler = () => {
|
|
103
|
-
if (!isResolved) {
|
|
104
|
-
isAborted = true;
|
|
105
|
-
console.log('Abort signal detected');
|
|
106
|
-
if (checkInterval)
|
|
107
|
-
clearInterval(checkInterval);
|
|
108
|
-
reject(new Error('Message aborted'));
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
// Abort signal 이벤트 리스너 등록
|
|
112
|
-
// eslint-disable-next-line no-undef
|
|
113
|
-
abortController.signal.addEventListener('abort', abortHandler, { once: true });
|
|
114
|
-
// 매우 짧은 간격으로 abort 상태 확인
|
|
115
|
-
checkInterval = setInterval(() => {
|
|
116
|
-
if (abortController.signal.aborted && !isResolved) {
|
|
117
|
-
isAborted = true;
|
|
118
|
-
clearInterval(checkInterval);
|
|
119
|
-
// eslint-disable-next-line no-undef
|
|
120
|
-
abortController.signal.removeEventListener('abort', abortHandler);
|
|
121
|
-
reject(new Error('Message aborted'));
|
|
122
|
-
}
|
|
123
|
-
}, 1); // 1ms마다 확인
|
|
124
|
-
// 원본 task 실행
|
|
125
|
-
task()
|
|
126
|
-
.then((result) => {
|
|
127
|
-
if (!isAborted && !isResolved) {
|
|
128
|
-
isResolved = true;
|
|
129
|
-
if (checkInterval)
|
|
130
|
-
clearInterval(checkInterval);
|
|
131
|
-
abortController.signal.removeEventListener('abort', abortHandler);
|
|
132
|
-
resolve(result);
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
.catch((error) => {
|
|
136
|
-
if (!isAborted && !isResolved) {
|
|
137
|
-
isResolved = true;
|
|
138
|
-
if (checkInterval)
|
|
139
|
-
clearInterval(checkInterval);
|
|
140
|
-
abortController.signal.removeEventListener('abort', abortHandler);
|
|
141
|
-
reject(error);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return promise;
|
|
145
|
-
}
|
|
146
100
|
}
|
|
147
101
|
exports.GracefulServerRMQ = GracefulServerRMQ;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolo-croket-dev/core",
|
|
3
|
-
"version": "1.7.25-slowquery.
|
|
3
|
+
"version": "1.7.25-slowquery.5",
|
|
4
4
|
"author": "Yolo Co., Ltd.",
|
|
5
5
|
"description": "Yolo commonization module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"license": "UNLICENSED",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@nestjs/common": "^8.2.3",
|
|
18
|
+
"@xuchaoqian/abortable-promise": "^1.11.2",
|
|
18
19
|
"@yolo-croket-dev/logger": "^1.0.15",
|
|
19
20
|
"@yolo-croket-dev/msa-logger": "^3.0.4",
|
|
20
21
|
"@yolo-croket-dev/redis": "^1.0.23",
|