You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-11-25 15:42:01 +02:00
updated cron jsvm bindings and generated types
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -104,12 +103,12 @@ func hooksBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
}
|
||||
|
||||
func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
jobs := cron.New()
|
||||
scheduler := cron.New()
|
||||
|
||||
loader.Set("cronAdd", func(jobId, cronExpr, handler string) {
|
||||
pr := goja.MustCompile("", "{("+handler+").apply(undefined)}", true)
|
||||
|
||||
err := jobs.Add(jobId, cronExpr, func() {
|
||||
err := scheduler.Add(jobId, cronExpr, func() {
|
||||
executors.run(func(executor *goja.Runtime) error {
|
||||
_, err := executor.RunProgram(pr)
|
||||
return err
|
||||
@@ -120,19 +119,28 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
}
|
||||
|
||||
// start the ticker (if not already)
|
||||
if jobs.Total() > 0 && !jobs.HasStarted() {
|
||||
jobs.Start()
|
||||
if app.IsBootstrapped() && scheduler.Total() > 0 && !scheduler.HasStarted() {
|
||||
scheduler.Start()
|
||||
}
|
||||
})
|
||||
|
||||
loader.Set("cronRemove", func(jobId string) {
|
||||
jobs.Remove(jobId)
|
||||
scheduler.Remove(jobId)
|
||||
|
||||
// stop the ticker if there are no other jobs
|
||||
if jobs.Total() == 0 {
|
||||
jobs.Stop()
|
||||
if scheduler.Total() == 0 {
|
||||
scheduler.Stop()
|
||||
}
|
||||
})
|
||||
|
||||
app.OnAfterBootstrap().Add(func(e *core.BootstrapEvent) error {
|
||||
// start the ticker (if not already)
|
||||
if scheduler.Total() > 0 && !scheduler.HasStarted() {
|
||||
scheduler.Start()
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func routerBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
@@ -534,10 +542,6 @@ func httpClientBinds(vm *goja.Runtime) {
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode < 200 || res.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("request failed with status %d", res.StatusCode)
|
||||
}
|
||||
|
||||
bodyRaw, _ := io.ReadAll(res.Body)
|
||||
|
||||
result := &sendResult{
|
||||
|
||||
Reference in New Issue
Block a user