From a0f8ab658f98d328dcd38e98e6880ac5ae5b2822 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 19 Mar 2024 22:05:37 -0400 Subject: [PATCH] Fix daily run scheduler not working --- api/daily.go | 14 +++++++------- api/generic.go | 7 ------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/api/daily.go b/api/daily.go index adcb47e..9a46af4 100644 --- a/api/daily.go +++ b/api/daily.go @@ -14,19 +14,20 @@ import ( "time" "github.com/Flashfyre/pokerogue-server/db" + "github.com/go-co-op/gocron" ) const secondsPerDay = 60 * 60 * 24 var ( - dailyRunSecret []byte - dailyRunSeed string + dailyRunScheduler = gocron.NewScheduler(time.UTC) + dailyRunSecret []byte + dailyRunSeed string ) func ScheduleDailyRunRefresh() { - scheduler.Every(1).Day().At("00:00").Do(func() { - InitDailyRun() - }) + dailyRunScheduler.Every(1).Day().At("00:00").Do(InitDailyRun) + dailyRunScheduler.StartAsync() } func InitDailyRun() { @@ -57,9 +58,8 @@ func InitDailyRun() { err = db.TryAddDailyRun(dailyRunSeed) if err != nil { 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 { diff --git a/api/generic.go b/api/generic.go index 0879eaf..bf93179 100644 --- a/api/generic.go +++ b/api/generic.go @@ -3,19 +3,12 @@ package api import ( "encoding/gob" "net/http" - "time" - - "github.com/go-co-op/gocron" ) type Server struct { Debug bool } -var ( - scheduler = gocron.NewScheduler(time.UTC) -) - func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { if s.Debug { w.Header().Set("Access-Control-Allow-Headers", "*")