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.
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
[BE] 입장 10분 전 푸시 알림 전송 기능 구현 (#483) #484
[BE] 입장 10분 전 푸시 알림 전송 기능 구현 (#483) #484
Changes from 38 commits
cbcad44
21f86ff
4c17ab6
2e4530d
4a77dd7
690f90f
323c6d9
1651604
3b308b5
97daba8
aa4e530
44ced57
bd7451b
221cac0
a083e3c
6aebcd5
da70c4d
4c20e30
03588d1
64759af
a29ae79
49c15e6
e253317
78e5820
7b4a210
fff1325
6995f68
639e228
ac669fc
dd9d56f
828935c
26fed9f
4577784
44c583b
a42051a
7d872a9
310cd14
ce2adf1
b081b35
40f9359
8965022
e374d66
d1f1792
6e06a21
94a3d55
e45fde3
e2b1eaa
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
entryAlertService
의create()
메서드는 DB에 저장하는 로직이라, 굳이@Async
로 등록을 해야할 필요가 있을까 싶네요.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.
entryAlertService의 create() 메서드가
@Transactional
메서드라서@Async
로 등록해줬습니다~!(
@Async
로 등록하지 않으면 기존 트랜잭션이 이미 커밋된 상태라서 insert문이 동작하지 않아요!propagation=REQUIRES_NEW로 하면 데드락 문제가 일어나고..)
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.
해당 메서드에
@Async
가 필요한 이유는EntryAlertEventListener
의addSchedule()
메서드에서 작업을 등록할 때 스케쥴러가 해당 메서드를 비동기로 실행하기 위함인가요?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.
네넵 정확합니다!
ScheduleThreadpool이 아닌 AsyncThreadPool에서 해당 메서드가 실행되도록 유도했습니다.
(ScheduleThreadpool corePoolSize: 1 / AsyncThreadPool corePoolSize: 8)
ScheduleThread는 그저 작업들이 대기하다가 특정 시각이 되면 메서드를 실행시키는 역할만 수행하도록 했습니다!
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.
X락을 거느라, 서버가 여러 개 생겼을 때 다른 서버들은 여기서 대기를 하겠네요.
해당 방법은 추후에 락을 걸더라도 락이 걸려있으면 바로 빠져나오게 할 방법이 필요하겠네요.
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.
대기를 하는 것을 의도한게 맞습니다!
여러 서버에서 동시에 실행되면 한 대의 서버에서만 실행됨을 보장해야해 X-lock을 걸어줬습니다!
X-lock 범위를 최소화하기 위해 실제 FCM 전송 로직은
@Async
로 분리해줬습니다!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.
redis를 이용한 분산락, mysql을 통한 분산락(https://techblog.woowahan.com/2631/) 등으로 추후에 변경을 모색해볼 수 있지만
나중에 저희가 정말 필요하다가 판단될 때 도입하는게 좋을 것 같습니당. (현재는 이렇게 하는게 가장 간단하니까요)
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.
EntryAlertFcmClient
클래스가 사라졌네요!TaskExecutor
의execute
메소드를 호출해서 비동기로 실행하는 것보다 다시EntryAlertFcmClient
를 추가해서 비동기로 실행하는 것은 어떤가요?그렇게 한다면 다음과 같이 실패한 요청을 로그로 남길 수 있을 것 같아요.
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.
sendAll에서 500건 이상이면 내부적으로 Async로 동작해서(500건씩 잘라서 별도의 스레드에서 전송) isSuccess 여부를 알아오기가 쉽지 않아요 ... ㅠㅠ
그걸 알기 위해선 위의 CompletableFuture 도입이 다시 필요해집니다 🥲
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.
EntryAlertFcmClient를 굳이 클래스로 분리하지 않은 이유는
fcmClient.sendAll(tokens, FCMChannel.ENTRY_ALERT, payload); 메서드를 호출하는 역할 뿐이어서
taskExecutor.execute 하는게 더 간단하고 Async로 돌아가는걸 메서드단에서 파악하기 쉬워서 분리하지않았는데
이 부분은 분리하는게 좋을까요?!
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.
아니면 500건 이상일때 비동기로 보내지않고 한 스레드에서 순차적으로 보내는 방법도 존재합니다..!!
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.
500건 이상일때 순차적으로 보내는 것도 좋겠네요. 😂
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.
FcmClient 를 추상화해준 이유가 추후에 IosFcmClient, webFcmClient를 고려한 것이 맞을까용?
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.
확장을 위한 추상화보다는 DIP를 위한 추상화입니다!!
FirebaseMessaging은 외부 라이브러리라고 판단해 infrastructure 레이어에 두기 위해서 추상화를 진행했습니다..!
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.
이렇게 달면 안돼나요? overflow
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.
놀랍게도 sendAll은 Async 메서드가 아닙니다..!
그 이유는 QR 상태 변경용 FCM에서는 이미 비동기 메서드에서 해당 메서드를 호출하기때문에
해당 메서드에
@Async
달면 두 번 Async 처리가 되더라구요!그래도 큰 문제는 없지만, 굳이 두 번 Async를 탈 필요는 없어서 저렇게 진행했습니다
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.
그러면
마찬가지로 요기도
이렇게 하면 안되는 것인가용?
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.
그래도 되긴 하는데...
entryAlertRepository.findByIdAndStatusForUpdate()
메서드가 락을 걸기도 하고, 트랜잭션 범위안에 있어서 이건 비동기로 재호출을 한 번 더 해야될 것 같네요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.
아아 x 락 범위가 있었네요 굿굿