mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-18 05:37:49 +02:00
trigger OnTerminate() hook on app.Restart() call
This commit is contained in:
parent
afbbc1d97c
commit
4c473385b2
@ -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
|
||||
|
||||
|
15
core/base.go
15
core/base.go
@ -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())
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,8 @@ type BootstrapEvent struct {
|
||||
}
|
||||
|
||||
type TerminateEvent struct {
|
||||
App App
|
||||
App App
|
||||
IsRestart bool
|
||||
}
|
||||
|
||||
type ServeEvent struct {
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user