补齐相关日志日志

This commit is contained in:
2026-09-16 00:23:49 +08:00
parent 8c2ea84939
commit b2e5eef3c8
39 changed files with 1576 additions and 176 deletions
+16 -7
View File
@@ -111,11 +111,20 @@ func runFortuneGenerationWithLock(client *Client, horoscopeDao *mysqldao.Horosco
defer cancel()
ok, lerr := redisdao.TryLock(ctx, lockKey, lockVal, 5*time.Minute)
if lerr != nil || !ok {
slog.Info("fortune generation already in progress, skip", "date", today)
if lerr != nil {
// Redis 故障与「其它实例正在执行」必须区分:前者当天运势可能缺失且无人知晓。
slog.ErrorContext(ctx, "fortune generation: acquire lock failed", "date", today, "error", lerr)
return
}
defer redisdao.Unlock(context.Background(), lockKey, lockVal)
if !ok {
slog.InfoContext(ctx, "fortune generation already in progress, skip", "date", today)
return
}
defer func() {
if uerr := redisdao.Unlock(context.Background(), lockKey, lockVal); uerr != nil {
slog.WarnContext(ctx, "fortune generation: release lock failed", "date", today, "error", uerr)
}
}()
runFortuneGeneration(client, horoscopeDao)
}
@@ -145,21 +154,21 @@ func EnsureTodayFortunes() {
today := now.Format("2006-01-02")
statDate, err := strconv.ParseInt(now.Format("20060102"), 10, 64)
if err != nil {
slog.Error("EnsureTodayFortunes: parse stat date failed", "error", err)
slog.ErrorContext(ctx, "EnsureTodayFortunes: parse stat date failed", "error", err)
return
}
horoscopes, err := horoscopeDao.HoroscopeGetByDate(ctx, statDate)
if err != nil {
slog.Warn("EnsureTodayFortunes: query today fortunes failed, will try to generate", "error", err, "date", today)
slog.WarnContext(ctx, "EnsureTodayFortunes: query today fortunes failed, will try to generate", "error", err, "date", today)
}
if len(horoscopes) >= 12 {
slog.Info("EnsureTodayFortunes: today fortunes already complete, skip", "date", today, "count", len(horoscopes))
slog.InfoContext(ctx, "EnsureTodayFortunes: today fortunes already complete, skip", "date", today, "count", len(horoscopes))
return
}
slog.Info("EnsureTodayFortunes: today fortunes incomplete, generating...",
slog.InfoContext(ctx, "EnsureTodayFortunes: today fortunes incomplete, generating...",
"date", today,
"existing", len(horoscopes),
"needed", 12,