aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/timer.go3
-rw-r--r--main.go1
-rw-r--r--user/level.go12
3 files changed, 7 insertions, 9 deletions
diff --git a/common/timer.go b/common/timer.go
index 553a8fd..aaea326 100644
--- a/common/timer.go
+++ b/common/timer.go
@@ -9,8 +9,7 @@ import (
func NewTimer(ctx context.Context, d time.Duration, fn func(context.Context, context.CancelFunc)) context.CancelFunc {
ctx, cancel := context.WithCancel(ctx)
- logger := bot.Logger(ctx).With("module", "timer")
- ctx = bot.SetLogger(ctx, logger)
+ ctx = bot.SetLogger(ctx, bot.Logger(ctx).With("module", "timer"))
go func(ctx context.Context, d time.Duration) {
ticker := time.NewTicker(d)
fn(ctx, cancel)
diff --git a/main.go b/main.go
index a1bc416..c3410c9 100644
--- a/main.go
+++ b/main.go
@@ -239,7 +239,6 @@ func setupTimers(ctx context.Context, dg *gokord.Session) {
// because logger was never set in this context
ctx = bot.SetLogger(ctx, dg.Logger())
- user.PeriodicReducer(ctx, dg)
stopPeriodicReducer = common.NewTimer(ctx, d, func(ctx context.Context, _ context.CancelFunc) {
user.PeriodicReducer(ctx, dg)
diff --git a/user/level.go b/user/level.go
index 0b839d1..2a5d494 100644
--- a/user/level.go
+++ b/user/level.go
@@ -51,25 +51,25 @@ func (c *CopaingCached) onNewLevel(ctx context.Context, dg bot.Session, level ui
func PeriodicReducer(ctx context.Context, dg bot.Session) {
PeriodicSaver(ctx, dg)
- logger := bot.Logger(ctx)
- logger.Debug("periodic reducer")
+ log := bot.Logger(ctx)
+ log.Debug("periodic reducer")
state := GetState(ctx)
n := 0
var wg sync.WaitGroup
for _, g := range dg.GuildAPI().State.Guilds() {
- n++
cfg := config.GetGuildConfig(ctx, g)
res := common.GetDB(ctx).
Model(&CopaingXP{}).
Where("guild_id = ? and created_at < ?", g, exp.TimeStampNDaysBefore(ctx, cfg.DaysXPRemains)).
Delete(&CopaingXP{})
if res.Error != nil {
- logger.Error("removing old xp", "error", res.Error, "guild", g)
+ log.Error("removing old xp", "error", res.Error, "guild", g)
continue
}
- logger.Debug("guild cleaned", "guild", g, "rows affected", res.RowsAffected)
+ n++
+ log.Debug("guild cleaned", "guild", g, "rows affected", res.RowsAffected)
wg.Go(func() {
syncCopaings(ctx, dg, state.Copaings(g))
@@ -78,7 +78,7 @@ func PeriodicReducer(ctx context.Context, dg bot.Session) {
wg.Wait()
- logger.Debug("periodic reduce finished", "guilds affected", n)
+ log.Debug("periodic reduce finished", "guilds affected", n)
}
func syncCopaings(ctx context.Context, dg bot.Session, ccs []CopaingCached) {