1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-18 13:47:47 +02:00

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

View File

@ -75,6 +75,9 @@
- Use `IS NOT` instead of `!=` as not-equal SQL query operator to handle the cases when comparing with nullable columns or expressions (eg. `json_extract` over `json` field).
_Based on my local dataset I wasn't able to find a significant difference in the performance between the 2 operators, but if you stumble on a query that you think may be affected negatively by this, please report it and I'll test it further._
- Trigger the `app.OnTerminate()` hook on `app.Restart()` call.
_A new bool `IsRestart` field was also added to the `core.TerminateEvent` event._
## v0.20.0-rc3

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())
}

View File

@ -70,7 +70,8 @@ type BootstrapEvent struct {
}
type TerminateEvent struct {
App App
App App
IsRestart bool
}
type ServeEvent struct {

View File

@ -169,8 +169,7 @@ func (pb *PocketBase) Execute() error {
return pb.OnTerminate().Trigger(&core.TerminateEvent{
App: pb,
}, func(e *core.TerminateEvent) error {
e.App.ResetBootstrapState()
return nil
return e.App.ResetBootstrapState()
})
}