added default panic-recover handling for the cron jobs
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
- Return the hidden record data fields for superusers realtime subscribers ([#7721](https://github.com/pocketbase/pocketbase/issues/7721)).
|
||||
|
||||
- Added default panic-recover handling for the cron jobs to avoid terminating the application on panic.
|
||||
|
||||
|
||||
## v0.39.0
|
||||
|
||||
|
||||
+3
-1
@@ -14,6 +14,8 @@ import (
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/pocketbase/tools/routine"
|
||||
)
|
||||
|
||||
// Cron is a crontab-like struct for tasks/jobs scheduling.
|
||||
@@ -222,7 +224,7 @@ func (c *Cron) runDue(t time.Time) {
|
||||
|
||||
for _, j := range c.jobs {
|
||||
if j.schedule.IsDue(moment) {
|
||||
go j.Run()
|
||||
routine.FireAndForget(j.Run)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func FireAndForget(f func(), wg ...*sync.WaitGroup) {
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Println("RECOVERED FROM PANIC (safe to ignore):", err)
|
||||
log.Println("[FireAndForget] RECOVERED FROM PANIC:", err)
|
||||
|
||||
stack := make([]byte, 2<<10) // 2 KB
|
||||
length := runtime.Stack(stack, false)
|
||||
|
||||
Reference in New Issue
Block a user