fixed metrics call

pull/60/head
f-fsantos 3 weeks ago
parent 3048e22787
commit b57eae4f0c

@ -91,14 +91,14 @@ func Init() error {
scheduler.Start() scheduler.Start()
if os.Getenv("AWS_ENDPOINT_URL_S3") != "" { if os.Getenv("AWS_ENDPOINT_URL_S3") != "" {
go func() { // go func() {
for { // for {
err = S3SaveMigration() // err = S3SaveMigration()
if err != nil { // if err != nil {
return // return
} // }
} // }
}() // }()
} }
return nil return nil

@ -39,7 +39,7 @@ func Update(uuid []byte, slot int, save any) error {
if save.TrainerId == 0 && save.SecretId == 0 { if save.TrainerId == 0 && save.SecretId == 0 {
return fmt.Errorf("invalid system data") return fmt.Errorf("invalid system data")
} }
ProcessSystemMetrics(save, uuid);
err = db.UpdateAccountStats(uuid, save.GameStats, save.VoucherCounts) err = db.UpdateAccountStats(uuid, save.GameStats, save.VoucherCounts)
if err != nil { if err != nil {
return fmt.Errorf("failed to update account stats: %s", err) return fmt.Errorf("failed to update account stats: %s", err)
@ -51,6 +51,7 @@ func Update(uuid []byte, slot int, save any) error {
if slot < 0 || slot >= defs.SessionSlotCount { if slot < 0 || slot >= defs.SessionSlotCount {
return fmt.Errorf("slot id %d out of range", slot) return fmt.Errorf("slot id %d out of range", slot)
} }
ProcessSessionMetrics(save, uuid)
return db.StoreSessionSaveData(uuid, save, slot) return db.StoreSessionSaveData(uuid, save, slot)
default: default:
@ -65,8 +66,10 @@ func ProcessSystemMetrics(save defs.SystemSaveData, uuid []byte) {
func ProcessSessionMetrics(save defs.SessionSaveData, uuid []byte) { func ProcessSessionMetrics(save defs.SessionSaveData, uuid []byte) {
err := Cache.Add(fmt.Sprintf("session-%x-%d", uuid, save.GameMode), uuid, time.Minute*5) err := Cache.Add(fmt.Sprintf("session-%x-%d", uuid, save.GameMode), uuid, time.Minute*5)
if err != nil { if err != nil {
log.Printf("already cached session")
return return
} }
log.Printf("increased game mode counter")
switch save.GameMode { switch save.GameMode {
case 0: case 0:
gameModeCounter.WithLabelValues("classic").Inc() gameModeCounter.WithLabelValues("classic").Inc()

Loading…
Cancel
Save