Skip to content

Commit

Permalink
refactor: 알림 처리 시간 변경 및 예외처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nyeroni committed Oct 30, 2024
1 parent 98603c0 commit c4e3a24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/main/java/yerong/wedle/common/utils/FcmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,22 @@ public static void broadCast(final List<String> registrationTokens, String title

MulticastMessage message = MulticastMessage.builder()
.setNotification(Notification.builder()
.setTitle(title) // 알림 제목
.setBody(body) // 알림 내용
.setTitle(title)
.setBody(body)
.build())
.setApnsConfig(ApnsConfig.builder()
.setAps(Aps.builder().setAlert(body).build()) // iOS에 맞춰 알림 내용 설정
.setAps(Aps.builder().setAlert(body).build())
.putHeader("apns-expiration", Long.toString(EXPIRED_TIME_FOR_UNIX))
.build())
.addAllTokens(registrationTokens)
.build();

BatchResponse response;
try {
response = FirebaseMessaging.getInstance().sendEachForMulticast(message);
BatchResponse response = FirebaseMessaging.getInstance().sendEachForMulticast(message);
pushSuccessValidate(registrationTokens, response);
} catch (FirebaseMessagingException e) {
e.printStackTrace();
// 예외 처리 추가 가능
System.out.println("FCM 메시지 전송 중 예외 발생: " + e.getMessage());
}
}

Expand All @@ -54,6 +53,12 @@ private static void pushSuccessValidate(final List<String> registrationTokens, f
System.out.println(response.getSuccessCount() + " messages were sent successfully.");
if (response.getFailureCount() > 0) {
System.out.println(response.getFailureCount() + " messages failed to send.");
response.getResponses().forEach(sendResponse -> {
if (!sendResponse.isSuccessful()) {
System.out.println("Failed to send message to token: " + sendResponse.getMessageId());
System.out.println("Error: " + sendResponse.getException().getMessage());
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private CalendarEvent getCalendarEventById(Long calendarId) {
}

@Transactional
@Scheduled(cron = "0 10 14 * * ?", zone = "Asia/Seoul")
@Scheduled(cron = "0 20 14 * * ?", zone = "Asia/Seoul")
public void sendNotifications() {
LocalDate today = LocalDate.now();
List<Notification> dueNotifications = notificationRepository.findByNotificationDate(today);
Expand Down

0 comments on commit c4e3a24

Please sign in to comment.