Skip to content

Add prep_stop callback#29

Merged
ieQu1 merged 2 commits into
masterfrom
dev/prep-stop
Jul 11, 2026
Merged

Add prep_stop callback#29
ieQu1 merged 2 commits into
masterfrom
dev/prep-stop

Conversation

@ieQu1

@ieQu1 ieQu1 commented Jul 10, 2026

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/2 hook registration and wire hook execution into shutdown/leave/remote-restart paths.
  • Extend classy:prep_stop/0 with a new classy:prep_stop/1 variant 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 thread src/classy_lib.erl
Comment on lines +124 to +127
Info = process_info(Pid, [current_stacktrace]),
demonitor(MRef, [flush]),
exit(Pid, kill),
{error, timeout}
{error, {timeout, Info}}
Comment thread src/classy_hook.erl
Comment on lines 229 to +233
?tp(critical, ?classy_hook_failure,
#{ reason => Err
, hook => Fun
, hookpoint => HookPoint
, args => Args
Comment thread src/classy.erl
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 thread src/classy_node.erl
Comment on lines +350 to +352
-doc false.
prep_stop(Reason) ->
classy_hook:foreach(?on_prep_stop, [Reason]).
@ieQu1 ieQu1 merged commit 13be4ba into master Jul 11, 2026
5 checks passed
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