Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ class OutboxAdapter(
override fun saveOutbox(outbox: Outbox) {
outboxRepository.save(outboxMapper.toEntity(outbox))
}

override fun deleteAll() {
outboxRepository.deleteAll()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dsm.pick2024.domain.outbox.port.out

interface DeleteOutboxPort {
fun deleteAll()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dsm.pick2024.domain.outbox.port.out

interface OutboxPort :
SaveOutboxPort
SaveOutboxPort,
DeleteOutboxPort
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dsm.pick2024.infrastructure.schedule

import dsm.pick2024.domain.application.port.out.DeleteApplicationPort
import dsm.pick2024.domain.outbox.port.out.DeleteOutboxPort
import dsm.pick2024.domain.attendance.port.`in`.ResetAttendanceUseCase
import dsm.pick2024.domain.classroom.port.out.DeleteClassRoomPort
import dsm.pick2024.domain.meal.port.`in`.MealUseCase
Expand Down Expand Up @@ -28,7 +29,8 @@ class ScheduleService(
private val updateWeekendMealUseCase: UpdateWeekendMealUseCase,
private val sendNotificationSelfStudyTeacherUseCase: SendNotificationSelfStudyTeacherUseCase,
private val notificationWeekendMealUseCase: NotificationWeekendMealUseCase,
private val sseRegistryPort: SseRegistryPort
private val sseRegistryPort: SseRegistryPort,
private val deleteOutboxPort: DeleteOutboxPort
) {
@Scheduled(cron = "0 30 20 * * ?", zone = "Asia/Seoul")
fun deleteTable() {
Expand Down Expand Up @@ -83,4 +85,9 @@ class ScheduleService(
fun sseHeartbeat() {
sseRegistryPort.sendHeartbeat()
}

@Scheduled(cron = "0 59 23 * * ?", zone = "Asia/Seoul")
fun cleanOutbox() {
deleteOutboxPort.deleteAll()
}
Comment on lines +89 to +92

@coderabbitai coderabbitai Bot May 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

전체 삭제 스케줄은 미처리 outbox 이벤트 유실 위험이 큽니다.

Line 91에서 매일 deleteAll()을 호출하면 아직 발행되지 않은 레코드까지 제거될 수 있습니다. 정리 대상은 최소한 발행 완료 + 보관기간 경과 조건으로 제한해야 합니다.

수정 방향 예시
 `@Scheduled`(cron = "0 59 23 * * ?", zone = "Asia/Seoul")
 fun cleanOutbox() {
-    deleteOutboxPort.deleteAll()
+    deleteOutboxPort.deletePublishedBefore(
+        cutoff = LocalDateTime.now(ZoneId.of("Asia/Seoul")).minusDays(1)
+    )
 }
// 포트/어댑터 측 추가 예시 (선택)
interface DeleteOutboxPort {
    fun deletePublishedBefore(cutoff: LocalDateTime): Long
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt`
around lines 89 - 92, The scheduled cleanOutbox() currently calls
deleteOutboxPort.deleteAll(), which risks removing unpublished/undelivered
events; change it to delete only events that are published and older than a
retention cutoff (e.g. compute cutoff =
LocalDateTime.now(ZoneId.of("Asia/Seoul")).minusDays(retentionDays)) and call a
new port method such as deletePublishedBefore(cutoff) (or add a
filterPublishedAndBefore(cutoff) to DeleteOutboxPort); update the
ScheduleService.cleanOutbox() to compute the cutoff and call that port method,
and implement the corresponding adapter/query to delete only records where
published=true (or publishedAt != null) AND publishedAt < cutoff.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

해당 스케줄은 서비스 정책을 고려한 의도적인 동작입니다. 서비스는 20:30 이후에는 신규 이벤트가 생성되지 않으며, 날짜가 지난 이벤트가 뒤늦게 전송될 경우 오히려 사용자 혼선을 유발할 가능성이 더 크다고 판단했습니다.

따라서 outbox 데이터는 매일 종료 시점에 전체 정리하도록 구현했으며, 미전송 이벤트가 일부 제거될 가능성은 서비스 정책상 허용 가능한 trade-off로 보고 있습니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@ByunDohwi, 설명 감사합니다. 서비스 정책상 20:30 이후 신규 이벤트가 생성되지 않으며, 날짜 경과 이벤트의 지연 전송이 오히려 사용자 혼선을 유발할 수 있다는 맥락을 이해했습니다. 해당 trade-off를 명시적으로 판단하신 것이므로 기존 구현 방식을 유지하는 것이 합리적입니다. 지적을 철회하겠습니다.

🐇 ~(=^‥^)/


✏️ Learnings added
Learnt from: ByunDohwi
Repo: DSM-PICK/PiCK_CORE_SERVER PR: 668
File: src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt:89-92
Timestamp: 2026-05-19T05:13:17.851Z
Learning: In `dsm/pick2024` (PiCK_CORE_SERVER), the `cleanOutbox()` scheduler in `src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt` intentionally calls `deleteOutboxPort.deleteAll()` (full deletion) at 23:59 every day. This is by design: the service generates no new outbox events after 20:30, and late delivery of stale events is considered more harmful (user confusion) than losing undelivered records. Deleting undelivered events at end-of-day is an explicitly accepted trade-off per service policy.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

}
Loading