Add prep_stop callback#29
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new “prep stop” hookpoint that allows business code to run callbacks before Classy lowers the run level to stopped (during shutdown, cluster leave, and remote-restart flows). It also enriches hook-timeout failures with timeout diagnostics and updates tests accordingly.
Changes:
- Add
classy:on_prep_stop/2hook registration and wire hook execution into shutdown/leave/remote-restart paths. - Extend
classy:prep_stop/0with a newclassy:prep_stop/1variant that passes a reason term. - Enhance hook-timeout reporting to include process stacktrace info; update tests to match the new timeout shape.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/classy_SUITE.erl | Updates timeout-related assertions to match the new {error, {timeout, _}} failure shape. |
| src/classy.erl | Exposes prep_stop/1 and adds on_prep_stop/2 hook registration API and docs. |
| src/classy_node.erl | Executes on_prep_stop hooks before lowering run level to stopped on shutdown/leave/remote restart. |
| src/classy_lib.erl | Adds timeout diagnostics by including process_info(..., current_stacktrace) data in timeout errors. |
| src/classy_internal.hrl | Introduces the ?on_prep_stop hookpoint macro. |
| src/classy_hook.erl | Adds hook call arguments to ?classy_hook_failure trace payload. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+124
to
+127
| Info = process_info(Pid, [current_stacktrace]), | ||
| demonitor(MRef, [flush]), | ||
| exit(Pid, kill), | ||
| {error, timeout} | ||
| {error, {timeout, Info}} |
Comment on lines
229
to
+233
| ?tp(critical, ?classy_hook_failure, | ||
| #{ reason => Err | ||
| , hook => Fun | ||
| , hookpoint => HookPoint | ||
| , args => Args |
Comment on lines
+514
to
+519
| -doc """ | ||
| Register a hook that is executed before shutting down business applications. | ||
|
|
||
| It is called before classy application starts the shutdown procedure, | ||
| as well when the site leaves a cluster or heals from a network partition. | ||
| """. |
Comment on lines
+350
to
+352
| -doc false. | ||
| prep_stop(Reason) -> | ||
| classy_hook:foreach(?on_prep_stop, [Reason]). |
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.
No description provided.