fix(cron): log CreateLongerRecords errors (#1926)

chore(cron): comment cron tasks with pocketbase warning
This commit is contained in:
Lars Lehtonen
2026-08-14 07:40:28 -07:00
committed by GitHub
parent cf90249519
commit 6d0b83f6de
2 changed files with 6 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ package records
import ( import (
"encoding/json" "encoding/json"
"log" "log/slog"
"math" "math"
"time" "time"
@@ -68,15 +68,18 @@ func (rm *RecordManager) CreateLongerRecords() {
}, },
} }
// wrap the operations in a transaction // wrap the operations in a transaction
// Pocketbase cron does not handle errors, log them here.
rm.app.RunInTransaction(func(txApp core.App) error { rm.app.RunInTransaction(func(txApp core.App) error {
var err error var err error
collections := [2]*core.Collection{} collections := [2]*core.Collection{}
collections[0], err = txApp.FindCachedCollectionByNameOrId("system_stats") collections[0], err = txApp.FindCachedCollectionByNameOrId("system_stats")
if err != nil { if err != nil {
slog.Error("Error finding cached collection using system stats:", "err", err)
return err return err
} }
collections[1], err = txApp.FindCachedCollectionByNameOrId("container_stats") collections[1], err = txApp.FindCachedCollectionByNameOrId("container_stats")
if err != nil { if err != nil {
slog.Error("Error finding cached collection using container stats:", "err", err)
return err return err
} }
var systems RecordIds var systems RecordIds
@@ -142,7 +145,7 @@ func (rm *RecordManager) CreateLongerRecords() {
longerRecord.Set("stats", rm.AverageContainerStats(db, recordIds)) longerRecord.Set("stats", rm.AverageContainerStats(db, recordIds))
} }
if err := txApp.SaveNoValidate(longerRecord); err != nil { if err := txApp.SaveNoValidate(longerRecord); err != nil {
log.Println("failed to save longer record", "err", err) slog.Error("failed to save longer record", "err", err)
} }
} }
} }

View File

@@ -12,6 +12,7 @@ import (
// Delete old records // Delete old records
func (rm *RecordManager) DeleteOldRecords() { func (rm *RecordManager) DeleteOldRecords() {
// Pocketbase cron does not handle errors, log them here.
rm.app.RunInTransaction(func(txApp core.App) error { rm.app.RunInTransaction(func(txApp core.App) error {
err := deleteOldSystemStats(txApp) err := deleteOldSystemStats(txApp)
if err != nil { if err != nil {