Configure cron to actually send to endpoint
This commit is contained in:
@@ -3,6 +3,8 @@ package cron
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/pterodactyl/wings/internal/database"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
@@ -19,12 +21,12 @@ func processActivityLogs(m *server.Manager) error {
|
||||
}
|
||||
defer processing.Store(false)
|
||||
|
||||
var b [][]byte
|
||||
var list [][]byte
|
||||
err := database.DB().View(func(tx *nutsdb.Tx) error {
|
||||
// Grab the oldest 100 activity events that have been logged and send them back to the
|
||||
// Panel for processing. Once completed, delete those events from the database and then
|
||||
// release the lock on this process.
|
||||
list, err := tx.LRange(database.ServerActivityBucket, []byte("events"), 0, 1)
|
||||
l, err := tx.LRange(database.ServerActivityBucket, []byte("events"), 0, 1)
|
||||
if err != nil {
|
||||
// This error is returned when the bucket doesn't exist, which is likely on the
|
||||
// first invocations of Wings since we haven't yet logged any data. There is nothing
|
||||
@@ -34,18 +36,25 @@ func processActivityLogs(m *server.Manager) error {
|
||||
}
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
b = list
|
||||
list = l
|
||||
return nil
|
||||
})
|
||||
|
||||
// If there is an error, return it. If there is no data to send to the Panel don't waste
|
||||
// an API call, just return here. WithStackIf will return "nil" when the value provided to
|
||||
// it is also nil.
|
||||
if err != nil || len(b) == 0 {
|
||||
if err != nil || len(list) == 0 {
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
if err := m.Client().SendActivityLogs(context.Background(), b); err != nil {
|
||||
var processed []json.RawMessage
|
||||
for _, l := range list {
|
||||
var v json.RawMessage
|
||||
if err := json.Unmarshal(l, &v); err != nil {
|
||||
log.WithField("error", errors.WithStack(err)).Warn("failed to parse activity event json, skipping entry")
|
||||
continue
|
||||
}
|
||||
processed = append(processed, v)
|
||||
}
|
||||
|
||||
if err := m.Client().SendActivityLogs(context.Background(), processed); err != nil {
|
||||
return errors.WrapIf(err, "cron: failed to send activity events to Panel")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user