-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 비활성화 토큰삭제 배치 처리 구현 #298
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb63f73
feat : retry 의존성 추가 및 config 생성
Daae-Kim 61b262c
feat : recover 로직 - 토큰 배치삭제 retry 모두 실패시 슬랙 알림 기능 구현
Daae-Kim 8b32bfc
feat : 비활성화 토큰 삭제 로직 구현
Daae-Kim d7878dd
chore : spotless apply
Daae-Kim 8b67f8f
refactor : aop 프록시 순서문제, transactional 로직 분리
Daae-Kim 947e2b3
refactor : flyway 마이그레이션 파일 생성
Daae-Kim 4e35730
chore : spotless 적용
Daae-Kim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
eeos/src/main/java/com/blackcompany/eeos/config/RetryConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.blackcompany.eeos.config; | ||
|
|
||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.retry.annotation.EnableRetry; | ||
|
|
||
| @Configuration | ||
| @EnableRetry | ||
| public class RetryConfig {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ava/com/blackcompany/eeos/notification/application/scheduler/PushTokenCleanScheduler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.blackcompany.eeos.notification.application.scheduler; | ||
|
|
||
| import com.blackcompany.eeos.notification.application.service.NotificationTokenService; | ||
| import com.blackcompany.eeos.notification.application.service.SlackNotificationService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.retry.annotation.Backoff; | ||
| import org.springframework.retry.annotation.Recover; | ||
| import org.springframework.retry.annotation.Retryable; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| public class PushTokenCleanScheduler { | ||
|
|
||
| private final SlackNotificationService slackNotificationService; | ||
| private final NotificationTokenService notificationTokenService; | ||
|
|
||
| private static final int INACTIVE_DAYS_THRESHOLD = 90; | ||
| private static final String SCHEDULER_NAME = "비활성화 토큰 삭제 스케줄러"; | ||
|
|
||
| /* | ||
| * 매주 토요일 새벽 3시 90일 이상 비활성화된 푸시 토큰 삭제 | ||
| * cron : 초 분 시 일 월 요일(6=토요일) | ||
| * */ | ||
|
|
||
| @Scheduled(cron = "0 0 3 * * 6") | ||
| @Retryable( | ||
| maxAttempts = 3, | ||
| backoff = @Backoff(delay = 2000), | ||
| recover = "recoverDeleteInactiveTokens") | ||
| public void deleteInactiveTokens() { | ||
| log.info("{} 시작", SCHEDULER_NAME); | ||
| int deleteCount = notificationTokenService.deleteInactiveTokens(); | ||
| log.info("{}개의 비활성화 토큰 삭제 완료", deleteCount); | ||
| } | ||
|
|
||
| @Recover | ||
| public void recoverDeleteInactiveTokens(Exception e) { | ||
| log.error("{} 실행 실패 - 모든 재시도 소진", SCHEDULER_NAME, e); | ||
|
|
||
| String errorMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName(); | ||
|
|
||
| if (errorMessage.length() > 300) { | ||
| errorMessage = errorMessage.substring(0, 300) + "...생략"; | ||
| } | ||
| slackNotificationService.sendSchedulerFailureMessage(SCHEDULER_NAME, errorMessage); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...java/com/blackcompany/eeos/notification/application/service/SlackNotificationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.blackcompany.eeos.notification.application.service; | ||
|
|
||
| import com.blackcompany.eeos.program.infra.api.slack.chat.client.SlackChatApiClient; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class SlackNotificationService { | ||
|
|
||
| private final SlackChatApiClient slackChatApiClient; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| @Value("${slack.bot.black-company.eeos}") | ||
| private String botToken; | ||
|
|
||
| @Value("${slack.channel.black-company.error-report}") | ||
| private String errorReportChannel; | ||
|
|
||
| public void sendSchedulerFailureMessage(String schedulerName, String errorMessage) { | ||
| String message = | ||
| String.format( | ||
| ":rotating_light: *스케줄러 실행 실패 알림*\n\n" | ||
| + "*Scheduler*\n `%s`\n\n" | ||
| + "*Failed At*\n`%s`\n\n" | ||
| + "*Error Message*\n`%s`\n\n", | ||
| schedulerName, | ||
| LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), | ||
| errorMessage); | ||
| sendMessage(message); | ||
| } | ||
|
|
||
| private void sendMessage(String text) { | ||
| try { | ||
| String blocks = | ||
| objectMapper.writeValueAsString( | ||
| List.of(Map.of("type", "section", "text", Map.of("type", "mrkdwn", "text", text)))); | ||
|
|
||
| slackChatApiClient.post( | ||
| "Bearer " + botToken, errorReportChannel, blocks, "EEOS Scheduler Bot"); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("Slack 알림 전송 실패", e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,4 +101,3 @@ CREATE TABLE `restrict_team_building` ( | |
|
|
||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용되지 않는 상수 제거
INACTIVE_DAYS_THRESHOLD상수가 이 클래스에서 사용되지 않습니다. 실제 삭제 로직은NotificationTokenService.deleteInactiveTokens()에서 자체 상수를 사용하고 있습니다.🔧 제안된 수정
- private static final int INACTIVE_DAYS_THRESHOLD = 90; private static final String SCHEDULER_NAME = "비활성화 토큰 삭제 스케줄러";🤖 Prompt for AI Agents