Add notification cleanup service and scheduler and Masking FCM Token#59
Merged
Conversation
Test Results109 tests 109 ✅ 1s ⏱️ Results for commit f713a53. ♻️ This comment has been updated with latest results. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an operational safety net for notifications by expiring stale PENDING notification logs on a daily schedule, and improves security of FCM token logging by masking tokens in log messages. It also introduces unit/integration tests to validate the cleanup behavior and token masking.
Changes:
- Add
NotificationCleanupService+NotificationCleanupSchedulerto bulk-expire oldPENDINGnotifications and record a Micrometer metric. - Extend
NotificationLogRepositorywith a JPQL bulk update (markExpiredBefore) and verify it with a real DB@DataJpaTest. - Mask FCM tokens in logs (prefix-only) and add tests for the masking behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/kotlin/com/moa/service/notification/NotificationCleanupService.kt | Implements bulk expiration of stale PENDING notifications and increments a cleanup metric by actual updated rows. |
| src/main/kotlin/com/moa/service/notification/NotificationCleanupScheduler.kt | Runs daily at 01:00 (Asia/Seoul) with ShedLock to invoke cleanup and log when unexpected stale records exist. |
| src/main/kotlin/com/moa/repository/NotificationLogRepository.kt | Adds markExpiredBefore(threshold) JPQL bulk update to set PENDING → EXPIRED for old scheduled dates. |
| src/main/kotlin/com/moa/service/FcmService.kt | Masks FCM tokens in exception logs and adds a reusable maskToken helper. |
| src/test/kotlin/com/moa/service/notification/NotificationCleanupServiceTest.kt | Unit tests ensure metrics increment only by actual updated row count (and not when 0 rows updated). |
| src/test/kotlin/com/moa/service/notification/NotificationCleanupSchedulerTest.kt | Unit tests verify correct threshold calculation/delegation and non-failing behavior when updates occur. |
| src/test/kotlin/com/moa/repository/NotificationLogRepositoryCleanupTest.kt | Integration tests validate the JPQL bulk update against a real DB and edge conditions (strict threshold, non-PENDING excluded). |
| src/test/kotlin/com/moa/service/FcmServiceTokenMaskTest.kt | Unit tests for token masking behavior (long/short/empty token cases). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Cleanup 스케줄러. | ||
| * | ||
| * 매일 새벽 1시에 [CLEANUP_THRESHOLD_DAYS]일 이상 지난 PENDING 을 |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces a robust cleanup mechanism for stale PENDING notifications, ensuring that any notifications scheduled before a certain threshold date are properly marked as EXPIRED. It also improves FCM token logging security and adds comprehensive tests for the new cleanup logic and token masking. The main changes are organized below:
Notification Cleanup Mechanism:
NotificationCleanupScheduler) that runs daily to expire PENDING notifications older than 7 days, logging a warning if any are found, which helps monitor missed dispatches.NotificationCleanupServiceto handle the bulk update of stale PENDING notifications to EXPIRED and increment a metric for monitoring.NotificationLogRepositorywith a new bulk update methodmarkExpiredBeforeto efficiently mark old PENDING notifications as EXPIRED using a JPQL query. [1] [2]Testing and Verification:
NotificationLogRepositoryCleanupTest) to verify the correctness of the bulk update JPQL query against a real database, ensuring only intended records are updated.NotificationCleanupServiceTest) and scheduler (NotificationCleanupSchedulerTest) to ensure correct metric counting and delegation logic. [1] [2]FCM Token Logging Security: