You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rogueserver/api/stats.go

48 lines
756 B
Go

package api
import (
"log"
8 months ago
"time"
"github.com/pagefaultgames/pokerogue-server/db"
"github.com/robfig/cron/v3"
)
var (
8 months ago
scheduler = cron.New(cron.WithLocation(time.UTC))
playerCount int
battleCount int
classicSessionCount int
)
func scheduleStatRefresh() {
scheduler.AddFunc("@every 30s", func() {
err := updateStats()
if err != nil {
log.Printf("failed to update stats: %s", err)
}
})
scheduler.Start()
}
func updateStats() error {
var err error
playerCount, err = db.FetchPlayerCount()
if err != nil {
return err
}
battleCount, err = db.FetchBattleCount()
if err != nil {
return err
}
classicSessionCount, err = db.FetchClassicSessionCount()
if err != nil {
return err
}
return nil
}