trigger the jsvm cron ticker only on app serve

This commit is contained in:
Gani Georgiev 2023-07-31 14:12:54 +03:00
parent cc8c855306
commit 9254ce46eb
3 changed files with 2584 additions and 2578 deletions

View File

@ -1,8 +1,10 @@
## v0.17.1 ## v0.17.1
- Use relative path when redirecting to the OAuth2 providers page in the Admin UI to support subpath deployments ([#3026](https://github.com/pocketbase/pocketbase/pull/3026); thanks @sonyarianto).
- Manually trigger the `OnBeforeServe` hook for `tests.ApiScenario` ([#3025](https://github.com/pocketbase/pocketbase/discussions/3025)). - Manually trigger the `OnBeforeServe` hook for `tests.ApiScenario` ([#3025](https://github.com/pocketbase/pocketbase/discussions/3025)).
- Use relative path when redirecting to the OAuth2 providers page in the Admin UI to support subpath deployments ([#3026](https://github.com/pocketbase/pocketbase/pull/3026); thanks @sonyarianto). - Trigger the JSVM `cronAdd()` handler only on app `serve` to prevent unexpected (and eventually duplicated) cron handler calls when custom console commands are used ([#3024](https://github.com/pocketbase/pocketbase/discussions/3024#discussioncomment-6592703)).
## v0.17.0 ## v0.17.0

View File

@ -105,6 +105,8 @@ func hooksBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) { func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
scheduler := cron.New() scheduler := cron.New()
var hasServeInited bool
loader.Set("cronAdd", func(jobId, cronExpr, handler string) { loader.Set("cronAdd", func(jobId, cronExpr, handler string) {
pr := goja.MustCompile("", "{("+handler+").apply(undefined)}", true) pr := goja.MustCompile("", "{("+handler+").apply(undefined)}", true)
@ -119,7 +121,7 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
} }
// start the ticker (if not already) // start the ticker (if not already)
if app.IsBootstrapped() && scheduler.Total() > 0 && !scheduler.HasStarted() { if hasServeInited && scheduler.Total() > 0 && !scheduler.HasStarted() {
scheduler.Start() scheduler.Start()
} }
}) })
@ -133,12 +135,14 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
} }
}) })
app.OnAfterBootstrap().Add(func(e *core.BootstrapEvent) error { app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
// start the ticker (if not already) // start the ticker (if not already)
if scheduler.Total() > 0 && !scheduler.HasStarted() { if scheduler.Total() > 0 && !scheduler.HasStarted() {
scheduler.Start() scheduler.Start()
} }
hasServeInited = true
return nil return nil
}) })
} }

File diff suppressed because it is too large Load Diff