tidy
This commit is contained in:
parent
a2f29b6ace
commit
939661556e
47
cron.go
47
cron.go
@ -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!")
|
||||
}
|
2
go.mod
2
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
|
||||
)
|
||||
|
2
go.sum
2
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=
|
||||
|
10
service.go
10
service.go
@ -22,15 +22,6 @@ 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")
|
||||
@ -39,4 +30,3 @@ func main() {
|
||||
|
||||
rpc(db, debug)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user