Skip to content

Add scheduler lock support for schedule tasks#50

Merged
subsub97 merged 2 commits intomainfrom
chore/blue-green
Apr 16, 2026
Merged

Add scheduler lock support for schedule tasks#50
subsub97 merged 2 commits intomainfrom
chore/blue-green

Conversation

@subsub97
Copy link
Copy Markdown
Collaborator

This pull request introduces distributed locking for scheduled tasks using ShedLock, updates scheduler configurations, and enhances application shutdown and monitoring settings. The main goal is to ensure that scheduled jobs are not executed concurrently in clustered environments, improving reliability and preventing duplicate task execution.

Distributed locking for scheduled jobs:

  • Added ShedLock integration by updating SchedulingConfig to provide a LockProvider bean and enabling @EnableSchedulerLock, ensuring only one instance of each scheduled task runs at a time across multiple nodes. (src/main/kotlin/com/moa/common/config/SchedulingConfig.kt, src/main/kotlin/com/moa/common/config/SchedulingConfig.ktR3-R36)
  • Annotated scheduled methods in NotificationBatchScheduler, NotificationDispatchScheduler, and PaydayNotificationBatchScheduler with @SchedulerLock, specifying unique lock names and lock durations to prevent concurrent execution. (src/main/kotlin/com/moa/service/notification/NotificationBatchScheduler.kt, [1] [2]; src/main/kotlin/com/moa/service/notification/NotificationDispatchScheduler.kt, [3] [4]; src/main/kotlin/com/moa/service/notification/PaydayNotificationBatchScheduler.kt, [5] [6]

Scheduler and shutdown configuration:

  • Configured a custom TaskScheduler bean with a thread pool and graceful shutdown settings to improve scheduling reliability and ensure tasks complete on shutdown. (src/main/kotlin/com/moa/common/config/SchedulingConfig.kt, src/main/kotlin/com/moa/common/config/SchedulingConfig.ktR3-R36)
  • Updated application-prod.yml to enable graceful server shutdown and set a shutdown timeout, ensuring all scheduled tasks have time to finish during application termination. (src/main/resources/application-prod.yml, src/main/resources/application-prod.ymlR11-R24)

Monitoring improvements:

  • Exposed the health endpoint via Actuator in production configuration for better observability, while restricting health details for security. (src/main/resources/application-prod.yml, src/main/resources/application-prod.ymlR11-R24)

Copilot AI review requested due to automatic review settings April 15, 2026 14:57
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

Test Results

53 tests   53 ✅  0s ⏱️
 6 suites   0 💤
 6 files     0 ❌

Results for commit 9bf4697.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces distributed locking for scheduled notification jobs using ShedLock to prevent concurrent execution across clustered deployments, along with production shutdown/health endpoint configuration updates.

Changes:

  • Add ShedLock dependencies and configure a JDBC-based LockProvider plus @EnableSchedulerLock.
  • Apply @SchedulerLock to notification-related scheduled jobs to enforce single-run semantics.
  • Update production config for graceful shutdown and expose the Actuator health endpoint.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
build.gradle.kts Adds ShedLock Spring + JDBC template provider dependencies.
src/main/kotlin/com/moa/common/config/SchedulingConfig.kt Enables scheduler locking; configures LockProvider and a pooled TaskScheduler.
src/main/kotlin/com/moa/service/notification/NotificationBatchScheduler.kt Adds lock annotation; adjusts cron schedule.
src/main/kotlin/com/moa/service/notification/NotificationDispatchScheduler.kt Adds lock annotation to per-minute dispatch job.
src/main/kotlin/com/moa/service/notification/PaydayNotificationBatchScheduler.kt Adds lock annotation to daily payday batch job.
src/main/resources/application-prod.yml Enables graceful shutdown; exposes health endpoint with no details.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +26
@Bean
fun lockProvider(dataSource: DataSource): LockProvider =
JdbcTemplateLockProvider(
JdbcTemplateLockProvider.Configuration.builder()
.withJdbcTemplate(JdbcTemplate(dataSource))
.usingDbTime()
.build()
)
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

JdbcTemplateLockProvider requires the ShedLock table to exist in the target database (and H2 for local runs). This PR adds the provider but doesn’t add any schema/migration/init script to create the lock table, which will cause runtime failures when a scheduled method tries to acquire a lock. Please add a DB migration or SQL init for the ShedLock table (and ensure it’s applied in prod/local) before enabling the provider.

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +18
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
@SchedulerLock(
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

The cron expression was changed from 0 20 0 * * * to 0 0 0 * * *, which moves the job time from 00:20 to 00:00. Since the PR description is focused on adding distributed locks (not changing schedules), please confirm this timing change is intended; otherwise revert to the previous schedule.

Copilot uses AI. Check for mistakes.
@subsub97 subsub97 merged commit 597cf6b into main Apr 16, 2026
3 checks passed
@subsub97 subsub97 deleted the chore/blue-green branch April 16, 2026 13:42
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