Repository navigation
fix(task)!: own scheduled tasks through application shutdown - #112
Merged
Merged
Conversation
This was referenced Sep 14, 2026
5 tasks done
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.
Scheduled tasks previously started during registration and discarded their handles. Stopping the server could leave both scheduling loops and their separately spawned executions running. Applications now retain a task owner, start work only after all registrations succeed, and stop scheduled work through the same shutdown signal as HTTP serving.
TaskSchedulera registration-only API.cronandintervaltake&mut self; standalone callers usestart()and retainRunningTasks. Application hooks already receive a mutable scheduler.JoinSetand execute each invocation inside its loop. Catch and log both callback-construction and future-polling panics without detaching an execution or adding aSyncbound to callbacks.shutdown_signalto both APIs, defaulting to Ctrl-C / Unix SIGTERM. Stop new executions immediately, let current ones finish, then abort and join remaining tasks aftertask_shutdown_timeout(30 seconds by default). The deadline runs concurrently with HTTP draining.README and MIGRATION document the registration change, standalone ownership, custom signals, and timeout configuration. Cancellation requires tasks to yield; application-created detached tasks and blocking work are outside this ownership. HTTP drain deadlines, public preparation, and application cleanup hooks remain follow-up work in #82.
Validation passed:
cargo check --workspace --all-featurescargo test -p gotchacargo test -p gotcha --all-featurescargo clippy --all-features --workspace -- -D warningsTests cover inert registration, graceful completion, timeout/drop/cancel cleanup for cron and interval jobs, and panic isolation with a Send-only callback. Public-API tests exercise both application APIs with real HTTP requests, including task timeout while HTTP is still draining, serving cancellation, and registration error/panic/cancellation. Subprocess tests verify clean exits on real SIGINT and SIGTERM without signalling the test runner.
All 11 GitHub CI checks passed for
a9f40a3a12bf04a03cb445e71bfa0cb6743f068e.Closes #93
Related to #82