mirror of
https://github.com/henrygd/beszel.git
synced 2026-08-19 16:57:47 +02:00
fix(cron): log CreateLongerRecords errors (#1926)
chore(cron): comment cron tasks with pocketbase warning
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user