Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 49 additions & 35 deletions apps/backend/libs/amqp/src/amqp.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Injectable, Logger } from '@nestjs/common'
import { AmqpConnection, Nack } from '@golevelup/nestjs-rabbitmq'
import {
AmqpConnection,
Nack,
type SubscriberHandler
} from '@golevelup/nestjs-rabbitmq'
import { Span, TraceService } from 'nestjs-otel'
Comment thread
zero1177 marked this conversation as resolved.
import {
CONSUME_CHANNEL,
Expand Down Expand Up @@ -31,32 +35,37 @@ export class JudgeAMQPService {
) {}

startSubscription() {
this.amqpConnection.createSubscriber(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async (msg: object, raw: any) => {
try {
// 메시지 타입에 따라 적절한 핸들러로 라우팅
if (
raw.properties.type === RUN_MESSAGE_TYPE ||
raw.properties.type === USER_TESTCASE_MESSAGE_TYPE
) {
if (this.messageHandlers?.onRunMessage) {
await this.messageHandlers.onRunMessage(
msg,
raw.properties.type === USER_TESTCASE_MESSAGE_TYPE
)
}
return
const handleJudgeMessage: SubscriberHandler<object> = async (msg, raw) => {
if (!msg || !raw) {
this.logger.error('Received empty judge message')
return new Nack(false)
}

try {
// 메시지 타입에 따라 적절한 핸들러로 라우팅
if (
raw.properties.type === RUN_MESSAGE_TYPE ||
raw.properties.type === USER_TESTCASE_MESSAGE_TYPE
) {
if (this.messageHandlers?.onRunMessage) {
await this.messageHandlers.onRunMessage(
msg,
raw.properties.type === USER_TESTCASE_MESSAGE_TYPE
)
}
return
}
Comment thread
zero1177 marked this conversation as resolved.

if (this.messageHandlers?.onJudgeMessage) {
await this.messageHandlers.onJudgeMessage(msg)
}
} catch (error) {
this.logger.error(error, 'Unexpected error in message handler')
return new Nack()
if (this.messageHandlers?.onJudgeMessage) {
Comment thread
zero1177 marked this conversation as resolved.
await this.messageHandlers.onJudgeMessage(msg)
}
},
} catch {
return new Nack(false)
}
Comment thread
zero1177 marked this conversation as resolved.
Comment on lines +62 to +64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

예외가 발생했을 때 에러 로그를 남기지 않고 Nack(false)만 반환하도록 변경되었습니다. 이로 인해 메시지 처리 중 예기치 못한 에러가 발생했을 때 원인을 파악하기 어려워질 수 있습니다. 이전 코드처럼 에러 객체와 함께 에러 로그를 남기도록 수정하는 것이 좋습니다.

      } catch (error) {
        this.logger.error(error, 'Unexpected error in message handler')
        return new Nack(false)
      }

}

this.amqpConnection.createSubscriber<object>(
handleJudgeMessage,
{
exchange: EXCHANGE,
routingKey: RESULT_KEY,
Expand Down Expand Up @@ -155,18 +164,23 @@ export class CheckAMQPService {
) {}

startSubscription() {
this.amqpConnection.createSubscriber(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async (msg: object, _: any) => {
try {
if (this.messageHandlers?.onCheckMessage) {
await this.messageHandlers?.onCheckMessage(msg)
}
} catch (error) {
this.logger.error(error, 'Unexpected error in handling check message')
return new Nack()
const handleCheckMessage: SubscriberHandler<object> = async (msg) => {
if (!msg) {
this.logger.error('Received empty check message')
return new Nack(false)
}

try {
if (this.messageHandlers?.onCheckMessage) {
await this.messageHandlers.onCheckMessage(msg)
}
Comment thread
zero1177 marked this conversation as resolved.
},
} catch {
return new Nack(false)
}
Comment on lines +177 to +179
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

CheckAMQPService애서더 마찬가지러 애기처 모탄 때러가 발생해슬 때 때러 로그러ᄱ 남겨더지 간고 단센하개 Nack(false)만 반헌하더로개 수정하거 이스너다.\n\n자애 발생 시 디버거ᄵᆼ걔 모니터링아 위해 catch (error)러ᄱ 터개 때러 로그러ᄱ 기러하더로개 수정하너개 을 건장하너다.

      } catch (error) {
        this.logger.error(error, 'Unexpected error in check message handler')
        return new Nack(false)
      }

Comment on lines +177 to +179
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

여기서도 예외 발생 시 에러 로그를 남기지 않고 Nack(false)만 반환하고 있습니다. 디버깅과 모니터링을 위해 이전처럼 에러 로그를 남기도록 수정하는 것이 좋습니다.

      } catch (error) {
        this.logger.error(error, 'Unexpected error in handling check message')
        return new Nack(false)
      }

}

this.amqpConnection.createSubscriber<object>(
handleCheckMessage,
{
exchange: CHECK_EXCHANGE,
routingKey: CHECK_RESULT_KEY,
Expand Down
Loading