Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

@efdao efdao Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSyncToken을 재시도하는 이유가 뭘까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요약: syncToken이 만료되었을 때 전체 일정을 가져오는 URL을 새로 생성하기 위해 사용합니다.

129번째 줄에서 url을 생성할 때 syncToken이 있다면 URL 쿼리에 syncToken을 추가하고 null 이라면 추가하지 않은(전체 일정을 가져오는) url을 생성합니다.

만약 API를 요청할 때 syncToken이 만료되거나 유효하지 않다면, RetryExecutor에서 DB의 syncToken을 null로 설정합니다. 그 이후에 재시도할 때는 이전에 사용한 URL이 아닌 syncToken이 포함되지 않은(전체 일정을 가져오는) URL로 재시도해야 합니다.

이전 코드를 보면 eventsUrl을 람다 함수 밖에서 만들어서 주입해주고 있는데요. 따로 조사한 결과, 람다 함수 외부에서 주입된 변수는 final로 처리되어 수정이 되지 않는다고 합니다. 따라서 새로 생성한 url을 적용하기 위해서 람다 함수 내부에서 url을 생성하기 위해 url 생성 과정에 필요한 getSyncToken을 재시도하고 있습니다.!

Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ public void deletePersonalEventFromGoogleCalender(PersonalEvent personalEvent) {
}

public void syncWithCalendar(String calendarId, User user) {
String syncToken = calendarService.getSyncToken(calendarId);
String eventsUrl = googleCalendarUrl.getSyncUrl(calendarId, syncToken, googleCalendarProperties.timeZone());

log.info("[syncWithCalendar] syncing user {} with token: {}", user.getName(), syncToken);

retryExecutor.executeCalendarApiWithRetry(
() -> {
String syncToken = calendarService.getSyncToken(calendarId);
String eventsUrl = googleCalendarUrl.getSyncUrl(calendarId, syncToken, googleCalendarProperties.timeZone());

log.info("[syncWithCalendar] syncing user {} with token: {}", user.getName(), syncToken);

GoogleEventResponse result = googleCalendarApi.syncEvents(eventsUrl, user.getAccessToken());
List<GoogleEvent> events = extractEventList(result);
extractSyncToken(calendarId, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public <T> T executeCalendarApiWithRetry(Supplier<T> action, User user, String c
userService.updateAccessToken(user, newAccessToken);
}
} catch (CalendarException e) {
log.error("Calendar exception: {}", e.getMessage());
log.error("Calendar Exception ErrorCode: {}", e.getErrorCode());
if (switch (e.getErrorCode()) {
case GC_EXPIRED_SYNC_TOKEN -> {
if (calendarId != null) {
Expand Down
Loading