moved some hardcoded values to config
This commit is contained in:
@@ -28,4 +28,16 @@ httpd:
|
||||
listen:
|
||||
- host: localhost
|
||||
port: 8000
|
||||
- socket: /tmp/csgowtf.sock
|
||||
- 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
|
@@ -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)
|
||||
|
22
main.go
22
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
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user