Skip to content

Commit

Permalink
7/12 배포 작업 (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc authored Jul 12, 2024
1 parent 32ea03e commit 1a8c424
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fabric.properties

# Log file
*.log
*.log.gz

# BlueJ files
*.ctxt
Expand Down
15 changes: 14 additions & 1 deletion src/main/kotlin/backend/itracker/alarm/service/AlarmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package backend.itracker.alarm.service

import backend.itracker.alarm.infra.slack.Color
import backend.itracker.alarm.infra.slack.SlackClient
import backend.itracker.alarm.service.event.FailedNotificationEvent
import backend.itracker.crawl.service.CrawlResultService
import backend.itracker.schedule.service.event.CrawlEndEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

private const val CRAWL_RESULT_TITLE = "[ 크롤링 결과 ]"
private const val CRAWL_RESULT_TITLE = "*[ 크롤링 결과 ]*"

@Component
class AlarmService (
Expand All @@ -31,4 +32,16 @@ class AlarmService (
false -> slackClient.sendNotification(CRAWL_RESULT_TITLE, Color.GREEN, messages)
}
}

@EventListener(FailedNotificationEvent::class)
fun alarmNotificationFailEvent(event: FailedNotificationEvent) {
slackClient.sendNotification(
"""
|*[ 알림 전송 실패 ]*
|*실패 사유* : ${event.getCause()}
""".trimMargin(),
Color.RED,
event.getMessages()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package backend.itracker.alarm.service.event

interface FailedNotificationEvent {

fun getMessages(): List<String>

fun getCause(): String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package backend.itracker.schedule.infra.notification.event

import backend.itracker.alarm.service.event.FailedNotificationEvent
import net.nurigo.sdk.message.model.FailedMessage

data class MessageSendFailEvent(
val failedMessages: List<FailedMessageInfo>,
val causeMessage: String?,
) : FailedNotificationEvent {

companion object {
fun of(failedMessageList: List<FailedMessage>, causeMessage: String?): MessageSendFailEvent {
return MessageSendFailEvent(
failedMessages = failedMessageList.map { FailedMessageInfo.from(it) },
causeMessage = causeMessage
)
}
}

override fun getMessages(): List<String> {
return failedMessages.map {
"""
*to*: ${it.to}
*from*: ${it.from}
*type*: ${it.type}
*country*: ${it.country}
*messageId*: ${it.messageId}
*statusCode*: ${it.statusCode}
*statusMessage*: ${it.statusMessage}
*accountId*: ${it.accountId}
""".trimIndent()
}
}

override fun getCause(): String? {
return causeMessage
}
}

data class FailedMessageInfo(
var to: String? = null,
var from: String? = null,
var type: String? = null,
var country: String? = null,
var messageId: String? = null,
var statusCode: String? = null,
var statusMessage: String? = null,
var accountId: String? = null
) {

companion object {
fun from(message: FailedMessage): FailedMessageInfo {
return FailedMessageInfo(
to = message.to,
from = message.from,
type = message.type,
country = message.country,
messageId = message.messageId,
statusCode = message.statusCode,
statusMessage = message.statusMessage,
accountId = message.accountId,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package backend.itracker.schedule.infra.notification.solapi

import backend.itracker.schedule.infra.notification.event.MessageSendFailEvent
import backend.itracker.schedule.infra.notification.solapi.config.NurigoKakaoChannelConfig
import backend.itracker.schedule.service.notification.NotificationSender
import backend.itracker.schedule.service.notification.dto.PriceChangeNotificationInfo
Expand All @@ -8,6 +9,7 @@ import net.nurigo.sdk.message.exception.NurigoMessageNotReceivedException
import net.nurigo.sdk.message.model.KakaoOption
import net.nurigo.sdk.message.model.Message
import net.nurigo.sdk.message.service.DefaultMessageService
import org.springframework.context.ApplicationEventPublisher
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component
import java.time.LocalDate
Expand All @@ -22,6 +24,7 @@ val logger = KotlinLogging.logger {}
class NotificationClient(
private val messageService: DefaultMessageService,
private val nurigoKakaoChannelConfig: NurigoKakaoChannelConfig,
private val eventPublisher: ApplicationEventPublisher,
) : NotificationSender {

override fun sendPriceChangeNotification(
Expand Down Expand Up @@ -53,10 +56,16 @@ class NotificationClient(
"""
[ 메세지 전송 실패 ]
실패 리스트 : ${exception.failedMessageList}
실패 메세지${exception.message}
""".trimIndent()
실패 메세지 : ${exception.message}
""".trimIndent()
}

eventPublisher.publishEvent(
MessageSendFailEvent.of(
exception.failedMessageList,
exception.message
)
)
}
}

}

0 comments on commit 1a8c424

Please sign in to comment.