-
Notifications
You must be signed in to change notification settings - Fork 16
fix(be): fix msg error for check & judge amqpService #3574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
60578a5
909be2b
ba94f09
3245b20
f3b475b
7e38028
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' | ||
| import { | ||
| CONSUME_CHANNEL, | ||
|
|
@@ -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 | ||
| } | ||
|
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) { | ||
|
zero1177 marked this conversation as resolved.
|
||
| await this.messageHandlers.onJudgeMessage(msg) | ||
| } | ||
| }, | ||
| } catch { | ||
| return new Nack(false) | ||
| } | ||
|
zero1177 marked this conversation as resolved.
Comment on lines
+62
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| this.amqpConnection.createSubscriber<object>( | ||
| handleJudgeMessage, | ||
| { | ||
| exchange: EXCHANGE, | ||
| routingKey: RESULT_KEY, | ||
|
|
@@ -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) | ||
| } | ||
|
zero1177 marked this conversation as resolved.
|
||
| }, | ||
| } catch { | ||
| return new Nack(false) | ||
| } | ||
|
Comment on lines
+177
to
+179
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
} catch (error) {
this.logger.error(error, 'Unexpected error in check message handler')
return new Nack(false)
}
Comment on lines
+177
to
+179
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| this.amqpConnection.createSubscriber<object>( | ||
| handleCheckMessage, | ||
| { | ||
| exchange: CHECK_EXCHANGE, | ||
| routingKey: CHECK_RESULT_KEY, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.