Add onTerminate hook to handle cluster termination#8
Merged
jdesboeufs merged 3 commits intomainfrom Oct 15, 2025
Merged
Conversation
Co-authored-by: jdesboeufs <1231232+jdesboeufs@users.noreply.github.com>
Co-authored-by: jdesboeufs <1231232+jdesboeufs@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add onTerminate hook to handle cluster termination
Add onTerminate hook to handle cluster termination
Oct 15, 2025
jdesboeufs
approved these changes
Oct 15, 2025
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.
Overview
This PR adds an optional
onTerminatecallback to the cluster that is invoked when the cluster terminates, addressing the need to handle cluster termination events.Motivation
When a cluster terminates (either explicitly via
end()or automatically due to failures), there was no way for applications to be notified and perform cleanup operations or logging. This hook provides a clean mechanism to handle these scenarios.Changes
Core Implementation
onTerminateparameter tocreateClusteroptionsterminateClusterfunction to invoke the hook after all nodes are killedUsage
The hook receives a
reasonparameter indicating why the cluster was terminated:'cluster stopped'- whencluster.end()is called explicitly'Too many consecutive failures'- when automatic termination occurs due to node startup failuresTesting
Added comprehensive test coverage:
end()methodAll existing tests continue to pass, and code coverage is maintained at 91.21%.
Backwards Compatibility
This is a non-breaking change. The
onTerminatehook is optional and existing code will continue to work without modification.Original prompt
Fixes #7
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.