-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlarmRingingNotificationScheduler.java
More file actions
51 lines (44 loc) · 1.96 KB
/
AlarmRingingNotificationScheduler.java
File metadata and controls
51 lines (44 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package akuma.whiplash.domains.alarm.application.scheduler;
import akuma.whiplash.domains.alarm.application.dto.etc.RingingPushInfo;
import akuma.whiplash.domains.alarm.application.dto.etc.RingingPushTargetDto;
import akuma.whiplash.domains.alarm.domain.service.AlarmQueryService;
import akuma.whiplash.infrastructure.firebase.FcmService;
import akuma.whiplash.infrastructure.redis.RedisService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class AlarmRingingNotificationScheduler {
private final AlarmQueryService alarmQueryService;
private final RedisService redisService;
private final FcmService fcmService;
// 10초 간격으로 실행
@Scheduled(fixedRate = 10000)
public void sendRingingAlarmNotifications() {
log.info("[AlarmRingingNotificationScheduler.sendRingingAlarmNotifications] 알람 울림 푸시 알림 전송 스케줄러 시작");
try {
List<RingingPushInfo> infos = alarmQueryService.getRingingNotificationTargets();
if (infos.isEmpty()) {
return;
}
List<RingingPushTargetDto> targets = infos.stream()
.flatMap(info -> redisService.getFcmTokens(info.memberId()).stream()
.map(token -> RingingPushTargetDto.builder()
.token(token)
.alarmId(info.alarmId())
.memberId(info.memberId())
.build()))
.toList();
if (targets.isEmpty()) {
return;
}
fcmService.sendRingingNotifications(targets);
} finally {
log.info("[AlarmRingingNotificationScheduler.sendRingingAlarmNotifications] 알람 울림 푸시 알림 전송 스케줄러 종료");
}
}
}