Skip to content

Add notification cleanup service and scheduler and Masking FCM Token#59

Merged
subsub97 merged 2 commits into
mainfrom
feat/notification-cleanup
May 31, 2026
Merged

Add notification cleanup service and scheduler and Masking FCM Token#59
subsub97 merged 2 commits into
mainfrom
feat/notification-cleanup

Conversation

@subsub97

Copy link
Copy Markdown
Collaborator

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:

  • Added a scheduled component (NotificationCleanupScheduler) that runs daily to expire PENDING notifications older than 7 days, logging a warning if any are found, which helps monitor missed dispatches.
  • Introduced NotificationCleanupService to handle the bulk update of stale PENDING notifications to EXPIRED and increment a metric for monitoring.
  • Extended NotificationLogRepository with a new bulk update method markExpiredBefore to efficiently mark old PENDING notifications as EXPIRED using a JPQL query. [1] [2]

Testing and Verification:

  • Added integration tests (NotificationLogRepositoryCleanupTest) to verify the correctness of the bulk update JPQL query against a real database, ensuring only intended records are updated.
  • Added unit tests for the cleanup service (NotificationCleanupServiceTest) and scheduler (NotificationCleanupSchedulerTest) to ensure correct metric counting and delegation logic. [1] [2]

FCM Token Logging Security:

  • Improved FCM token logging by masking all but the first 8 characters of the token in logs, reducing risk of sensitive data exposure. Added unit tests for the masking logic. [1] [2] [3]

Copilot AI review requested due to automatic review settings May 31, 2026 07:12
@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown

Test Results

109 tests   109 ✅  1s ⏱️
 18 suites    0 💤
 18 files      0 ❌

Results for commit f713a53.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 + NotificationCleanupScheduler to bulk-expire old PENDING notifications and record a Micrometer metric.
  • Extend NotificationLogRepository with 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 PENDINGEXPIRED 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.

Comment thread src/main/kotlin/com/moa/service/notification/NotificationCleanupScheduler.kt Outdated
/**
* Cleanup 스케줄러.
*
* 매일 새벽 1시에 [CLEANUP_THRESHOLD_DAYS]일 이상 지난 PENDING 을
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@subsub97 subsub97 merged commit 0b9b820 into main May 31, 2026
3 checks passed
@subsub97 subsub97 deleted the feat/notification-cleanup branch May 31, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants