From 939661556e8bce7d3554bdb4cb77c2c45c997b9b Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 25 Nov 2024 17:19:45 -0800 Subject: [PATCH] tidy --- cron.go | 47 ----------------------------------------------- go.mod | 2 +- go.sum | 2 -- service.go | 22 ++++++---------------- 4 files changed, 7 insertions(+), 66 deletions(-) delete mode 100644 cron.go diff --git a/cron.go b/cron.go deleted file mode 100644 index 66bf898..0000000 --- a/cron.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "context" - "time" - - "git.itzana.me/strafesnet/data-service/internal/datastore" - "git.itzana.me/strafesnet/data-service/internal/model" - log "github.com/sirupsen/logrus" -) - -func cron(db datastore.Datastore, debug bool) { - log.Infoln("Starting cron...") - - // Cleanup old events - if err := db.Events().Clean(context.Background()); err != nil { - log.WithField("error", err).Errorln("cron: failed to clean events") - } - - // Cleanup dead servers - if err := db.Servers().DeleteByLastUpdated(context.Background(), time.Now().Add(-time.Minute*10)); err != nil { - log.WithField("error", err).Errorln("cron: failed to clean dead servers") - } - - // Calculate ranks - pairList, err := db.Times().DistinctStylePairs(context.Background()) - if err != nil { - log.WithField("error", err).Errorln("cron: failed to update ranks") - } else { - for i := 0; i < len(pairList); i++ { - if err := db.Ranks().UpdateAll(context.Background(), pairList[i].StyleID, pairList[i].GameID, pairList[i].ModeID); err != nil { - log.WithField("error", err).Errorln("cron: failed to update ranks") - } - } - - if err := db.Ranks().UpdateRankCalc(context.Background()); err != nil { - log.WithError(err).Errorln("cron: failed to update rank calc table") - } - - db.Events().Create(context.Background(), model.Event{ - Event: "Ranks.Updated", - Date: time.Now(), - }) - } - - log.Infoln("Cron completed!") -} diff --git a/go.mod b/go.mod index 906c4af..360546f 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.0 google.golang.org/grpc v1.48.0 - google.golang.org/protobuf v1.33.0 gorm.io/driver/postgres v1.1.0 gorm.io/gorm v1.21.11 ) @@ -43,4 +42,5 @@ require ( golang.org/x/sys v0.5.0 // indirect golang.org/x/text v0.3.7 // indirect google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect + google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index df76e15..6c2d8c7 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.itzana.me/strafesnet/go-grpc v0.0.0-20240302215338-8ebbc7cffb0a h1:679jxkSaW3ZEj0XW6v+sr3Wr3LcmHRbbDLmo80xty5s= -git.itzana.me/strafesnet/go-grpc v0.0.0-20240302215338-8ebbc7cffb0a/go.mod h1:X7XTRUScRkBWq8q8bplbeso105RPDlnY7J6Wy1IwBMs= git.itzana.me/strafesnet/go-grpc v0.0.0-20240719190059-5e33b807d0f7 h1:QD8ejgS2ePLkrngJEiijYouv+W87jtl/oSGJ6z5pwCY= git.itzana.me/strafesnet/go-grpc v0.0.0-20240719190059-5e33b807d0f7/go.mod h1:X7XTRUScRkBWq8q8bplbeso105RPDlnY7J6Wy1IwBMs= git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9 h1:7lU6jyR7S7Rhh1dnUp7GyIRHUTBXZagw8F4n4hOyxLw= diff --git a/service.go b/service.go index 9739305..e0da180 100644 --- a/service.go +++ b/service.go @@ -22,21 +22,11 @@ func main() { // Postgres - if os.Getenv("CRON") == "true" { - db, err := gormstore.New(false) - if err != nil { - log.WithField("error", err).Fatalln("database startup failed") - return - } - - cron(db, debug) - } else { - db, err := gormstore.New(true) - if err != nil { - log.WithField("error", err).Fatalln("database startup failed") - return - } - - rpc(db, debug) + db, err := gormstore.New(true) + if err != nil { + log.WithField("error", err).Fatalln("database startup failed") + return } + + rpc(db, debug) }