refactor(scheduler): clean JVM shutdown for batch-style entry point#609
Merged
Conversation
Wrap SpringApplication.run in SpringApplication.exit + System.exit so the context is closed (PreDestroy hooks, JPA pool drain, etc.) and the JVM returns a deterministic exit code after the CommandLineRunner completes. Matches the standard Spring Boot batch-style entry point and is what k8s cron jobs need. Analyzer left unchanged for now; will be applied separately. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Apply the reviewer's full suggestion (#534): SchedulerApplication implements CommandLineRunner + ExitCodeGenerator directly, wraps the work in try/catch, tracks exitCode, and reports it via getExitCode(). SpringApplication.exit propagates that to System.exit so the k8s CronJob pod status reflects batch outcome. Removes the prior @bean CommandLineRunner. Also adds spring.main.banner-mode=off per the suggestion. Verified with the boot jar: - empty H2 schema (runner throws) -> caught, JPA pool drained, exit 1 - schema preloaded, no PENDING ops -> exit 0 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
Summary
Follow-up to PR #534 addressing reviewer feedback on the scheduler entry point.
The
SchedulerApplicationalready usedCommandLineRunner, butSpringApplication.run(...)left the context open after the runner finished — JPA pool / Spring framework threads (non-daemon) can keep the JVM alive, and the exit code does not reflect batch outcome. For a k8s cron-job-style batch app, that is the wrong shape.Wraps
SpringApplication.runinSpringApplication.exit+System.exitso the context is closed (@PreDestroy, JPA pool drain, etc.) and the JVM exits with a deterministic exit code after theCommandLineRunnercompletes. This is the standard Spring Boot batch-style entry point.Scope
Only
SchedulerApplication.AnalyzerApplicationhas the same shape and will be updated separately to keep this PR minimal and focused on the scheduler review thread.Changes
Testing Done
./gradlew :apps:optimizer:schedulerapp:buildpasses (compile + checkstyle + spotbugs).Additional Information