From d5b151946e7e0003444acdc8e8c926b12784597d Mon Sep 17 00:00:00 2001 From: kwon204 Date: Sun, 18 May 2025 17:51:36 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20sync=5Ftoken=EC=9D=B4=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=EB=90=98=EA=B1=B0=EB=82=98=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EB=95=8C=EB=8A=94=20?= =?UTF-8?q?=EC=9E=AC=EC=8B=9C=EB=8F=84=EB=A5=BC=20=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0=20=EC=98=88=EC=99=B8=EB=A5=BC=20=EB=82=A0?= =?UTF-8?q?=EB=A6=AC=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 예외를 날린 후 구글 서버에 500 에러 응답을 보낸다. - 500응답을 받은 구글 서버가 웹훅 알림을 한 번 더 보낸다. - 이때 다시 일정을 가져오면서 sync_token을 업데이트한다. --- .../java/endolphin/backend/global/util/RetryExecutor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java b/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java index 045721db..444ee1f3 100644 --- a/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java +++ b/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java @@ -40,13 +40,13 @@ public T executeCalendarApiWithRetry(Supplier 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) { calendarService.clearSyncToken(calendarId); } - yield false; + throw e; } case GC_BAD_REQUEST_ERROR, GC_CONFLICT_ERROR, GC_GONE_ERROR -> true; default -> false; From e2c2715ce8f3b7c89e7d47f242554d4d7fe8be14 Mon Sep 17 00:00:00 2001 From: kwon204 Date: Sun, 18 May 2025 18:08:57 +0900 Subject: [PATCH 2/4] =?UTF-8?q?test:=20=EC=9E=AC=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sync_token이 유효하지 않을 경우 재시도 하지 않고 예외를 발생 시키는 것으로 수정 --- .../backend/global/util/RetryExecutorTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java b/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java index b8ee9d8e..a893fb59 100644 --- a/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java +++ b/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java @@ -98,13 +98,9 @@ public void testExecuteCalendarApiWithRetry_calendarExpiredSyncTokenThenSuccess( return "success"; }; - // When - String result = retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1"); - - // Then - assertThat(result).isEqualTo("success"); - assertThat(counter.get()).isEqualTo(2); - then(calendarService).should().clearSyncToken("calendarId1"); + // When & Then + assertThatThrownBy(() -> retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1")) + .isInstanceOf(CalendarException.class); } @Test From 61d84fb1ca5f94580e7d2c7c3e7c8fb9edaa458b Mon Sep 17 00:00:00 2001 From: kwon204 Date: Fri, 30 May 2025 18:25:16 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20sync=5Ftoken=20=EB=A7=8C=EB=A3=8C=20?= =?UTF-8?q?=EC=8B=9C=20=EC=A0=84=EC=B2=B4=20=EC=9D=BC=EC=A0=95=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EB=8A=94=20API=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 람다 함수 내부에서 url을 생성하도록 수정 --- .../global/google/GoogleCalendarService.java | 10 +++++----- .../backend/global/util/RetryExecutor.java | 2 +- .../backend/global/util/RetryExecutorTest.java | 13 ++++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/endolphin/backend/global/google/GoogleCalendarService.java b/backend/src/main/java/endolphin/backend/global/google/GoogleCalendarService.java index 468a28f0..c876e916 100644 --- a/backend/src/main/java/endolphin/backend/global/google/GoogleCalendarService.java +++ b/backend/src/main/java/endolphin/backend/global/google/GoogleCalendarService.java @@ -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 events = extractEventList(result); extractSyncToken(calendarId, result); diff --git a/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java b/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java index 444ee1f3..6e663c87 100644 --- a/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java +++ b/backend/src/main/java/endolphin/backend/global/util/RetryExecutor.java @@ -46,7 +46,7 @@ public T executeCalendarApiWithRetry(Supplier action, User user, String c if (calendarId != null) { calendarService.clearSyncToken(calendarId); } - throw e; + yield false; } case GC_BAD_REQUEST_ERROR, GC_CONFLICT_ERROR, GC_GONE_ERROR -> true; default -> false; diff --git a/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java b/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java index a893fb59..55db1070 100644 --- a/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java +++ b/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java @@ -98,9 +98,16 @@ public void testExecuteCalendarApiWithRetry_calendarExpiredSyncTokenThenSuccess( return "success"; }; - // When & Then - assertThatThrownBy(() -> retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1")) - .isInstanceOf(CalendarException.class); +// // When & Then +// assertThatThrownBy(() -> retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1")) +// .isInstanceOf(CalendarException.class); + // When + String result = retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1"); + + // Then + assertThat(result).isEqualTo("success"); + assertThat(counter.get()).isEqualTo(2); + then(calendarService).should().clearSyncToken("calendarId1"); } @Test From afd03f361986623464799174deeb235bf5207861 Mon Sep 17 00:00:00 2001 From: kwon204 Date: Fri, 30 May 2025 18:29:35 +0900 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/endolphin/backend/global/util/RetryExecutorTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java b/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java index 55db1070..b8ee9d8e 100644 --- a/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java +++ b/backend/src/test/java/endolphin/backend/global/util/RetryExecutorTest.java @@ -98,9 +98,6 @@ public void testExecuteCalendarApiWithRetry_calendarExpiredSyncTokenThenSuccess( return "success"; }; -// // When & Then -// assertThatThrownBy(() -> retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1")) -// .isInstanceOf(CalendarException.class); // When String result = retryExecutor.executeCalendarApiWithRetry(supplier, user, "calendarId1");