diff --git a/config_example.yaml b/config_example.yaml index 68b9226..724171d 100644 --- a/config_example.yaml +++ b/config_example.yaml @@ -28,4 +28,16 @@ httpd: listen: - host: localhost port: 8000 - - socket: /tmp/csgowtf.sock \ No newline at end of file + - socket: /tmp/csgowtf.sock + +csgowtfd: + # how often should a profile be refreshed from steam + # more on format: https://pkg.go.dev/time#ParseDuration + # default: 168h (7d) + profile_update: "168h" + # how often should csgowtfd check for a new match + # format same as profile_update + # default: 30m + sharecode_update: "30m" + # days in which demos expire + demos_expire: 30 \ No newline at end of file diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index a2c77f0..9f78d88 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -449,9 +449,14 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { // clear cache for player for _, p := range players { - // TODO: cache only real meta stats in only one key - _ = d.cache.Delete(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, p.ID, 4)) - _ = d.cache.Delete(context.Background(), fmt.Sprintf(utils.MatchMetaCacheKey, p.ID)) + err = d.cache.Delete(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, p.ID)) + if err != nil { + log.Warningf("[DL] Unable to delete cache key %s: %v", fmt.Sprintf(utils.SideMetaCacheKey, p.ID), err) + } + err = d.cache.Delete(context.Background(), fmt.Sprintf(utils.MatchMetaCacheKey, p.ID)) + if err != nil { + log.Warningf("[DL] Unable to delete cache key %s: %v", fmt.Sprintf(utils.MatchMetaCacheKey, p.ID), err) + } } err = d.dp.ParseDemo(demo) diff --git a/main.go b/main.go index 2474609..de6d3e9 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,6 @@ var ( db *ent.Client rdb *redis.Client rdc *cache.Cache - firstHK = true rL ratelimit.Limiter configFlag = flag.String("config", "config.yaml", "Set config to use") journalLogFlag = flag.Bool("journal", false, "Log to systemd journal instead of stdout") @@ -48,14 +47,17 @@ var ( func housekeeping() { for { - if !firstHK { - time.Sleep(5 * time.Minute) + time.Sleep(5 * time.Minute) + + dur, err := time.ParseDuration(conf.Csgowtfd.ProfileUpdate) + if err != nil { + log.Warningf("[HK] Unable to parse config option profile_update %s: %v", conf.Csgowtfd.ProfileUpdate, err) + dur, _ = time.ParseDuration("168h") } - firstHK = false // update players from steam tPlayerNeedSteamUpdate, err := db.Player.Query().Where( - player.SteamUpdatedLTE(time.Now().UTC().AddDate(0, 0, -1)), + player.SteamUpdatedLTE(time.Now().UTC().Add(dur * -1)), ).All(context.Background()) if err != nil { log.Errorf("[HK] Can't query players: %v", err) @@ -76,10 +78,16 @@ func housekeeping() { continue } + dur, err = time.ParseDuration(conf.Csgowtfd.SharecodeUpdate) + if err != nil { + log.Warningf("[HK] Unable to parse config option sharecode_update %s: %v", conf.Csgowtfd.SharecodeUpdate, err) + dur, _ = time.ParseDuration("30m") + } + tPlayerNeedShareCodeUpdate, err := db.Player.Query().Where( player.And( player.Or( - player.SharecodeUpdatedLTE(time.Now().UTC().Add(time.Duration(-30)*time.Minute)), + player.SharecodeUpdatedLTE(time.Now().UTC().Add(dur*-1)), player.SharecodeUpdatedIsNil(), ), player.Not(player.AuthCodeIsNil()), @@ -120,7 +128,7 @@ func housekeeping() { } // try parsing demos not parsed - tMatches, err := db.Match.Query().Where(match.And(match.DateGT(time.Now().UTC().AddDate(0, 0, -30)), match.DemoParsed(false))).All(context.Background()) + tMatches, err := db.Match.Query().Where(match.And(match.DateGT(time.Now().UTC().AddDate(0, 0, conf.Csgowtfd.DemosExpire)), match.DemoParsed(false))).All(context.Background()) if err != nil { log.Warningf("[HK] Failure getting matches to retry parsing: %v", err) continue diff --git a/utils/utils.go b/utils/utils.go index 9a0b955..96bb898 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -57,6 +57,11 @@ type Conf struct { Port int } } + Csgowtfd struct { + ProfileUpdate string `yaml:"profile_update"` + SharecodeUpdate string `yaml:"sharecode_update"` + DemosExpire int `yaml:"demos_expire"` + } } type CommunityXML struct {