Skip to content

Commit

Permalink
PH-76 application context 종료시 디스코드 웹훅 알림 전송하도록 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
w-seok committed Apr 16, 2024
1 parent 4c86419 commit e6e550e
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -70,6 +71,23 @@ public void onStart(final ApplicationStartedEvent event) {
}
}

/**
* spring application 종료시 시간 및 ip 기록(의도치 않은 종료 체크)
* @param event
*/
@EventListener(ContextClosedEvent.class)
public void onClosed(ContextClosedEvent event) {
isInit = StringUtils.hasText(alertChannel) && StringUtils.hasText(serverStatusChannel);
if (isInit) {
String title = "[%s] 어플리케이션 종료".formatted(appName);
String description = "public: %s | local: %s".formatted(publicIp, localIp);
String fieldContent = "%s초".formatted(((double)ManagementFactory.getRuntimeMXBean().getUptime() / 1000));
DiscordMessage message = toMessage(title, description, COLOR_GREEN,
Collections.singletonList(new EmbedObject.Field("spring closed", fieldContent, true)));
sendMessage(serverStatusChannel, message);
}
}

@Override
public void alertInfo(String title, String infoMessage) {

Expand All @@ -93,7 +111,7 @@ public void alertError(String title, String errorMessage) {

/**
* 디스코드 웹훅 전송
* Todo: 추후 에러 응답이 자주 발생할 경우 retry 로직 추가 및 read timeout 조정 우선은 30초
* Todo: 추후 에러 응답이 자주 발생할 경우 retry 로직 추가 및 read timeout 조정 우선은 10초
* @param channel
* @param message
*/
Expand Down

0 comments on commit e6e550e

Please sign in to comment.