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)).
|
- 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
|
## v0.39.0
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -14,6 +14,8 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pocketbase/pocketbase/tools/routine"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cron is a crontab-like struct for tasks/jobs scheduling.
|
// 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 {
|
for _, j := range c.jobs {
|
||||||
if j.schedule.IsDue(moment) {
|
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() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
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
|
stack := make([]byte, 2<<10) // 2 KB
|
||||||
length := runtime.Stack(stack, false)
|
length := runtime.Stack(stack, false)
|
||||||
|
|||||||
Reference in New Issue
Block a user