feat: 기존 푸시 메시지 전송 로직에 최대 3회 재시도 처리 로직 추가
This commit is contained in:
parent
971683a81e
commit
c1d4c1ff1d
|
@ -29,8 +29,14 @@ class FcmService {
|
||||||
creatorId: Long? = null,
|
creatorId: Long? = null,
|
||||||
auditionId: Long? = null
|
auditionId: Long? = null
|
||||||
) {
|
) {
|
||||||
if (tokens.isNotEmpty()) {
|
if (tokens.isEmpty()) return
|
||||||
logger.info("os: $container")
|
logger.info("os: $container")
|
||||||
|
|
||||||
|
var targets = tokens
|
||||||
|
val maxAttempts = 3
|
||||||
|
var attempt = 1
|
||||||
|
|
||||||
|
while (attempt <= maxAttempts && targets.isNotEmpty()) {
|
||||||
val multicastMessage = MulticastMessage.builder()
|
val multicastMessage = MulticastMessage.builder()
|
||||||
.addAllTokens(tokens)
|
.addAllTokens(tokens)
|
||||||
|
|
||||||
|
@ -85,8 +91,34 @@ class FcmService {
|
||||||
}
|
}
|
||||||
|
|
||||||
val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build())
|
val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build())
|
||||||
logger.info("[FCM] ✅ 성공: ${response.successCount}")
|
val failedTokens = mutableListOf<String>()
|
||||||
logger.info("[FCM] ❌ 실패: ${response.failureCount}")
|
|
||||||
|
response.responses.forEachIndexed { index, res ->
|
||||||
|
if (!res.isSuccessful) {
|
||||||
|
val exception = res.exception
|
||||||
|
val token = targets[index]
|
||||||
|
|
||||||
|
if (exception?.messagingErrorCode == MessagingErrorCode.UNREGISTERED) {
|
||||||
|
logger.error("[FCM] ❌ UNREGISTERED → $token")
|
||||||
|
// 필요 시 DB에서 삭제
|
||||||
|
} else {
|
||||||
|
logger.error("[FCM] ❌ 실패: $token / ${exception?.messagingErrorCode}")
|
||||||
|
failedTokens.add(token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failedTokens.isEmpty()) {
|
||||||
|
logger.info("[FCM] ✅ 전체 전송 성공")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
targets = failedTokens
|
||||||
|
attempt++
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targets.isNotEmpty()) {
|
||||||
|
logger.error("[FCM] ❌ 최종 실패 대상 ${targets.size}명 → $targets")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue