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.
40 lines
660 B
Go
40 lines
660 B
Go
8 months ago
|
package api
|
||
|
|
||
|
import (
|
||
7 months ago
|
"log"
|
||
|
"time"
|
||
8 months ago
|
|
||
7 months ago
|
"github.com/go-co-op/gocron"
|
||
7 months ago
|
"github.com/pagefaultgames/pokerogue-server/db"
|
||
8 months ago
|
)
|
||
|
|
||
7 months ago
|
var (
|
||
7 months ago
|
statScheduler = gocron.NewScheduler(time.UTC)
|
||
|
playerCount int
|
||
|
battleCount int
|
||
|
classicSessionCount int
|
||
7 months ago
|
)
|
||
8 months ago
|
|
||
7 months ago
|
func scheduleStatRefresh() {
|
||
7 months ago
|
statScheduler.Every(10).Second().Do(updateStats)
|
||
|
statScheduler.StartAsync()
|
||
7 months ago
|
}
|
||
|
|
||
7 months ago
|
func updateStats() {
|
||
7 months ago
|
var err error
|
||
|
playerCount, err = db.FetchPlayerCount()
|
||
8 months ago
|
if err != nil {
|
||
7 months ago
|
log.Print(err)
|
||
8 months ago
|
}
|
||
7 months ago
|
|
||
7 months ago
|
battleCount, err = db.FetchBattleCount()
|
||
|
if err != nil {
|
||
|
log.Print(err)
|
||
|
}
|
||
7 months ago
|
|
||
7 months ago
|
classicSessionCount, err = db.FetchClassicSessionCount()
|
||
|
if err != nil {
|
||
|
log.Print(err)
|
||
|
}
|
||
7 months ago
|
}
|