moved some hardcoded values to config
This commit is contained in:
@@ -29,3 +29,15 @@ httpd:
|
|||||||
- host: localhost
|
- host: localhost
|
||||||
port: 8000
|
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
|
// clear cache for player
|
||||||
for _, p := range players {
|
for _, p := range players {
|
||||||
// TODO: cache only real meta stats in only one key
|
err = d.cache.Delete(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, p.ID))
|
||||||
_ = d.cache.Delete(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, p.ID, 4))
|
if err != nil {
|
||||||
_ = d.cache.Delete(context.Background(), fmt.Sprintf(utils.MatchMetaCacheKey, p.ID))
|
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)
|
err = d.dp.ParseDemo(demo)
|
||||||
|
20
main.go
20
main.go
@@ -39,7 +39,6 @@ var (
|
|||||||
db *ent.Client
|
db *ent.Client
|
||||||
rdb *redis.Client
|
rdb *redis.Client
|
||||||
rdc *cache.Cache
|
rdc *cache.Cache
|
||||||
firstHK = true
|
|
||||||
rL ratelimit.Limiter
|
rL ratelimit.Limiter
|
||||||
configFlag = flag.String("config", "config.yaml", "Set config to use")
|
configFlag = flag.String("config", "config.yaml", "Set config to use")
|
||||||
journalLogFlag = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
journalLogFlag = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
||||||
@@ -48,14 +47,17 @@ var (
|
|||||||
|
|
||||||
func housekeeping() {
|
func housekeeping() {
|
||||||
for {
|
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
|
// update players from steam
|
||||||
tPlayerNeedSteamUpdate, err := db.Player.Query().Where(
|
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())
|
).All(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("[HK] Can't query players: %v", err)
|
log.Errorf("[HK] Can't query players: %v", err)
|
||||||
@@ -76,10 +78,16 @@ func housekeeping() {
|
|||||||
continue
|
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(
|
tPlayerNeedShareCodeUpdate, err := db.Player.Query().Where(
|
||||||
player.And(
|
player.And(
|
||||||
player.Or(
|
player.Or(
|
||||||
player.SharecodeUpdatedLTE(time.Now().UTC().Add(time.Duration(-30)*time.Minute)),
|
player.SharecodeUpdatedLTE(time.Now().UTC().Add(dur*-1)),
|
||||||
player.SharecodeUpdatedIsNil(),
|
player.SharecodeUpdatedIsNil(),
|
||||||
),
|
),
|
||||||
player.Not(player.AuthCodeIsNil()),
|
player.Not(player.AuthCodeIsNil()),
|
||||||
@@ -120,7 +128,7 @@ func housekeeping() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try parsing demos not parsed
|
// 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 {
|
if err != nil {
|
||||||
log.Warningf("[HK] Failure getting matches to retry parsing: %v", err)
|
log.Warningf("[HK] Failure getting matches to retry parsing: %v", err)
|
||||||
continue
|
continue
|
||||||
|
@@ -57,6 +57,11 @@ type Conf struct {
|
|||||||
Port int
|
Port int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Csgowtfd struct {
|
||||||
|
ProfileUpdate string `yaml:"profile_update"`
|
||||||
|
SharecodeUpdate string `yaml:"sharecode_update"`
|
||||||
|
DemosExpire int `yaml:"demos_expire"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommunityXML struct {
|
type CommunityXML struct {
|
||||||
|
Reference in New Issue
Block a user