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
+6 -2
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) {
scheduler := cron.New()
var hasServeInited bool
loader.Set("cronAdd", func(jobId, cronExpr, handler string) {
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)
if app.IsBootstrapped() && scheduler.Total() > 0 && !scheduler.HasStarted() {
if hasServeInited && scheduler.Total() > 0 && !scheduler.HasStarted() {
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)
if scheduler.Total() > 0 && !scheduler.HasStarted() {
scheduler.Start()
}
hasServeInited = true
return nil
})
}
File diff suppressed because it is too large Load Diff