Fix daily run scheduler not working

pull/1/head
Flashfyre 9 months ago
parent be04408336
commit a0f8ab658f

@ -14,19 +14,20 @@ import (
"time" "time"
"github.com/Flashfyre/pokerogue-server/db" "github.com/Flashfyre/pokerogue-server/db"
"github.com/go-co-op/gocron"
) )
const secondsPerDay = 60 * 60 * 24 const secondsPerDay = 60 * 60 * 24
var ( var (
dailyRunScheduler = gocron.NewScheduler(time.UTC)
dailyRunSecret []byte dailyRunSecret []byte
dailyRunSeed string dailyRunSeed string
) )
func ScheduleDailyRunRefresh() { func ScheduleDailyRunRefresh() {
scheduler.Every(1).Day().At("00:00").Do(func() { dailyRunScheduler.Every(1).Day().At("00:00").Do(InitDailyRun)
InitDailyRun() dailyRunScheduler.StartAsync()
})
} }
func InitDailyRun() { func InitDailyRun() {
@ -57,9 +58,8 @@ func InitDailyRun() {
err = db.TryAddDailyRun(dailyRunSeed) err = db.TryAddDailyRun(dailyRunSeed)
if err != nil { if err != nil {
log.Print(err.Error()) log.Print(err.Error())
} else {
log.Printf("Daily Run Seed: %s", dailyRunSeed)
} }
log.Printf("Daily Run Seed: %s", dailyRunSeed)
} }
func DeriveDailyRunSeed(seedTime time.Time) []byte { func DeriveDailyRunSeed(seedTime time.Time) []byte {

@ -3,19 +3,12 @@ package api
import ( import (
"encoding/gob" "encoding/gob"
"net/http" "net/http"
"time"
"github.com/go-co-op/gocron"
) )
type Server struct { type Server struct {
Debug bool Debug bool
} }
var (
scheduler = gocron.NewScheduler(time.UTC)
)
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if s.Debug { if s.Debug {
w.Header().Set("Access-Control-Allow-Headers", "*") w.Header().Set("Access-Control-Allow-Headers", "*")

Loading…
Cancel
Save