2024-03-23 21:34:18 -04:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2024-04-01 21:42:48 -04:00
|
|
|
"log"
|
|
|
|
"time"
|
2024-03-23 21:34:18 -04:00
|
|
|
|
|
|
|
"github.com/Flashfyre/pokerogue-server/db"
|
2024-04-01 21:42:48 -04:00
|
|
|
"github.com/go-co-op/gocron"
|
2024-03-23 21:34:18 -04:00
|
|
|
)
|
|
|
|
|
2024-04-01 21:42:48 -04:00
|
|
|
var (
|
2024-04-06 18:15:47 -04:00
|
|
|
statScheduler = gocron.NewScheduler(time.UTC)
|
|
|
|
playerCount int
|
|
|
|
battleCount int
|
|
|
|
classicSessionCount int
|
2024-04-01 21:42:48 -04:00
|
|
|
)
|
2024-03-23 21:34:18 -04:00
|
|
|
|
2024-04-06 18:15:47 -04:00
|
|
|
func ScheduleStatRefresh() {
|
|
|
|
statScheduler.Every(10).Second().Do(updateStats)
|
|
|
|
statScheduler.StartAsync()
|
2024-04-01 21:42:48 -04:00
|
|
|
}
|
|
|
|
|
2024-04-06 18:15:47 -04:00
|
|
|
func updateStats() {
|
2024-04-01 21:42:48 -04:00
|
|
|
var err error
|
|
|
|
playerCount, err = db.FetchPlayerCount()
|
2024-03-23 21:34:18 -04:00
|
|
|
if err != nil {
|
2024-04-01 22:54:55 -04:00
|
|
|
log.Print(err)
|
2024-03-23 21:34:18 -04:00
|
|
|
}
|
2024-04-08 20:44:36 -04:00
|
|
|
|
2024-04-06 18:15:47 -04:00
|
|
|
battleCount, err = db.FetchBattleCount()
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
2024-04-08 20:44:36 -04:00
|
|
|
|
2024-04-06 18:15:47 -04:00
|
|
|
classicSessionCount, err = db.FetchClassicSessionCount()
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
2024-04-01 21:42:48 -04:00
|
|
|
}
|