@yolo-croket-dev/core 1.7.25-slowquery.11 → 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.
@@ -44,6 +44,7 @@ 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
+ const abortable_promise_1 = require("@xuchaoqian/abortable-promise");
47
48
  // import Logger from '@yolo-croket-dev/logger';
48
49
  const functions_1 = require("../functions");
49
50
  const exceptions_1 = require("../exceptions");
@@ -179,7 +180,16 @@ let RPCInterceptor = class RPCInterceptor {
179
180
  const arg = args[0];
180
181
  const rmq = args[1];
181
182
  // 메시지에서 AbortController 가져오기
182
- const abortController = rmq.args[0].abortController;
183
+ // const abortController = (rmq as any).args[0].abortController;
184
+ const abortController = new AbortController();
185
+ const handler = context.getHandler();
186
+ console.log('args: ', args);
187
+ console.log('context: ', context);
188
+ const abortablePromise = new abortable_promise_1.AbortablePromise((...args) => handler(...args), abortController.signal);
189
+ console.log('abortablePromise: ', abortablePromise);
190
+ // (context as any).handler = abortablePromise;
191
+ console.log('handler: ', handler);
192
+ console.log('context: ', context);
183
193
  // const messageId = (rmq as any).messageId;
184
194
  // if (!abortController) {
185
195
  // // AbortController가 없으면 기본 처리
@@ -346,11 +356,10 @@ let RPCInterceptor = class RPCInterceptor {
346
356
  // logger.debug(`=> (${traceId}): ${JSON.stringify(this.keyCutter(JSON.stringify(content)))}`);
347
357
  }
348
358
  this.gracefulShutdownService.pushActiveInterceptors(execInterceptor);
349
- const abort$ = (0, rxjs_1.fromEvent)(abortController.signal, 'abort');
350
359
  // eslint-disable-next-line consistent-return
351
360
  return next
352
361
  .handle()
353
- .pipe((0, operators_1.takeUntil)(abort$),
362
+ .pipe(
354
363
  // timeout(1000 * 60 * 29), // 30분 타임아웃
355
364
  (0, operators_1.timeout)(1000 * 3), // 30분 타임아웃
356
365
  (0, operators_1.tap)({
@@ -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
- try {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-croket-dev/core",
3
- "version": "1.7.25-slowquery.11",
3
+ "version": "1.7.25-slowquery.13",
4
4
  "author": "Yolo Co., Ltd.",
5
5
  "description": "Yolo commonization module",
6
6
  "main": "index.js",