mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-19 14:17:48 +02:00
[#6481] allowed calling cronAdd and cronRemove from inside other JSVM handlers
This commit is contained in:
parent
4e148f7224
commit
33613b27b0
@ -9,14 +9,15 @@
|
||||
For example, to disable MFA for the OAuth2 auth could be expressed as `@request.context != "oauth2"` MFA rule.
|
||||
(@todo docs)
|
||||
|
||||
- Added `$os.stat(file)` JSVM helper ([#6407](https://github.com/pocketbase/pocketbase/discussions/6407)).
|
||||
|
||||
- Added log warning for `async` marked JSVM handlers and resolve when possible the returned `Promise` as fallback ([#6476](https://github.com/pocketbase/pocketbase/issues/6476)).
|
||||
|
||||
- Added `store.Store.SetFunc(key, func(old T) new T)` to set/update a store value with the return result of the callback in a concurrent safe manner.
|
||||
|
||||
- Added `subscription.Message.WriteSSE(w, id)` for writing an SSE formatted message into the provided writer interface (_used mostly to assist with the unit testing_).
|
||||
|
||||
- Added `$os.stat(file)` JSVM helper ([#6407](https://github.com/pocketbase/pocketbase/discussions/6407)).
|
||||
|
||||
- Added log warning for `async` marked JSVM handlers and resolve when possible the returned `Promise` as fallback ([#6476](https://github.com/pocketbase/pocketbase/issues/6476)).
|
||||
|
||||
- Allowed calling `cronAdd`, `cronRemove` from inside other JSVM handlers ([#6481](https://github.com/pocketbase/pocketbase/discussions/6481)).
|
||||
|
||||
- Bumped the default request read and write timeouts to 5mins (_old 3mins_) to accommodate slower internet connections and larger file uploads/downloads.
|
||||
_If you want to change them you can modify the `OnServe` hook's `ServeEvent.ReadTimeout/WriteTimeout` fields as shown in [#6550](https://github.com/pocketbase/pocketbase/discussions/6550#discussioncomment-12364515)._
|
||||
|
@ -101,7 +101,7 @@ func hooksBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
}
|
||||
|
||||
func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
loader.Set("cronAdd", func(jobId, cronExpr, handler string) {
|
||||
cronAdd := func(jobId, cronExpr, handler string) {
|
||||
pr := goja.MustCompile(defaultScriptPath, "{("+handler+").apply(undefined)}", true)
|
||||
|
||||
err := app.Cron().Add(jobId, cronExpr, func() {
|
||||
@ -121,28 +121,27 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
|
||||
if err != nil {
|
||||
panic("[cronAdd] failed to register cron job " + jobId + ": " + err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
loader.Set("cronAdd", cronAdd)
|
||||
|
||||
// note: it is not necessary needed but it is here for consistency
|
||||
loader.Set("cronRemove", func(jobId string) {
|
||||
cronRemove := func(jobId string) {
|
||||
app.Cron().Remove(jobId)
|
||||
})
|
||||
}
|
||||
loader.Set("cronRemove", cronRemove)
|
||||
|
||||
// register the removal helper also in the executors to allow removing cron jobs from everywhere
|
||||
oldFactory := executors.factory
|
||||
executors.factory = func() *goja.Runtime {
|
||||
vm := oldFactory()
|
||||
|
||||
vm.Set("cronRemove", func(jobId string) {
|
||||
app.Cron().Remove(jobId)
|
||||
})
|
||||
vm.Set("cronAdd", cronAdd)
|
||||
vm.Set("cronRemove", cronRemove)
|
||||
|
||||
return vm
|
||||
}
|
||||
for _, item := range executors.items {
|
||||
item.vm.Set("cronRemove", func(jobId string) {
|
||||
app.Cron().Remove(jobId)
|
||||
})
|
||||
item.vm.Set("cronAdd", cronAdd)
|
||||
item.vm.Set("cronRemove", cronRemove)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1438,7 +1438,7 @@ func TestCronBindsCount(t *testing.T) {
|
||||
testBindsCount(vm, "this", 2, t)
|
||||
|
||||
pool.run(func(poolVM *goja.Runtime) error {
|
||||
testBindsCount(poolVM, "this", 1, t)
|
||||
testBindsCount(poolVM, "this", 2, t)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user