trigger OnTerminate() hook on app.Restart() call

This commit is contained in:
Gani Georgiev
2023-12-08 15:45:58 +02:00
parent afbbc1d97c
commit 4c473385b2
4 changed files with 21 additions and 3 deletions
+15
View File
@@ -553,6 +553,21 @@ func (app *BaseApp) Restart() error {
return err
}
// restart the app bootstrap as a fallback in case the
// terminate event or execve fails for some reason
defer app.Bootstrap()
// optimistically trigger the terminate event
terminateErr := app.OnTerminate().Trigger(&TerminateEvent{
App: app,
IsRestart: true,
}, func(e *TerminateEvent) error {
return e.App.ResetBootstrapState()
})
if terminateErr != nil {
return terminateErr
}
return syscall.Exec(execPath, os.Args, os.Environ())
}
+2 -1
View File
@@ -70,7 +70,8 @@ type BootstrapEvent struct {
}
type TerminateEvent struct {
App App
App App
IsRestart bool
}
type ServeEvent struct {