diff --git a/internal/seckill/scheduler.go b/internal/seckill/scheduler.go index df1067a..84345b8 100644 --- a/internal/seckill/scheduler.go +++ b/internal/seckill/scheduler.go @@ -916,10 +916,10 @@ func (s *Scheduler) calibrateDouyuTime(label string) types.TimeCalibration { } smoothed := s.smoothedOffset() logger.SetDouyuOffset(smoothed) - logger.LogEvent("时间", "success", "%s校准完成: 斗鱼估算=%s 偏移=%dms 平滑偏移=%dms 误差<=%dms RTT=%dms 采样=%d 来源=%s", + calibration.Offset = smoothed + logger.LogEvent("时间", "success", "%s校准完成: 斗鱼估算=%s 平滑偏移=%dms 误差<=%dms RTT=%dms 采样=%d 来源=%s", label, calibration.EstimatedServerNow().In(constants.CST).Format("2006-01-02 15:04:05.000"), - calibration.Offset.Milliseconds(), smoothed.Milliseconds(), calibration.ErrorBound.Milliseconds(), calibration.RTT.Milliseconds(), @@ -1207,23 +1207,25 @@ func (s *Scheduler) scheduleTimers(accountProducts map[string]string, targetTime if remain < 0 { remain = 0 } - warmupRemain := remain - warmupBeforeTrigger - if warmupRemain < 0 { - warmupRemain = 0 - } s.scheduleMu.Lock() defer s.scheduleMu.Unlock() - gen := atomic.AddInt64(&s.warmupGen, 1) - s.replaceTimerLocked(&s.warmupSchedule, warmupRemain, func() { - if atomic.LoadInt64(&s.warmupGen) != gen { - return + if !resync { + warmupRemain := remain - warmupBeforeTrigger + if warmupRemain < 0 { + warmupRemain = 0 } - logger.LogEvent("预热", "success", "预热触发: 本地=%s", time.Now().In(constants.CST).Format("15:04:05.000")) - settings := s.settingsSnapshot() - attempts := s.buildAttempts(accountProducts, settings.attempts) - s.warmupAttempts(attempts) - }) + gen := atomic.AddInt64(&s.warmupGen, 1) + s.replaceTimerLocked(&s.warmupSchedule, warmupRemain, func() { + if atomic.LoadInt64(&s.warmupGen) != gen { + return + } + logger.LogEvent("预热", "success", "预热触发: 本地=%s", time.Now().In(constants.CST).Format("15:04:05.000")) + settings := s.settingsSnapshot() + attempts := s.buildAttempts(accountProducts, settings.attempts) + s.warmupAttempts(attempts) + }) + } s.replaceTimerLocked(&s.schedule, remain, func() { now := time.Now() estimatedServer := now.Add(calibration.Offset) @@ -1239,14 +1241,13 @@ func (s *Scheduler) scheduleTimers(accountProducts map[string]string, targetTime s.RunNow(accountProducts) }) if resync { - logger.LogEvent("定时", "success", "临近复校已应用: 目标=%s 触发=%s 斗鱼估算=%s 本地偏移=%dms 误差<=%dms RTT=%dms 预热=%s", + logger.LogEvent("定时", "success", "临近复校已应用: 目标=%s 触发=%s 斗鱼估算=%s 偏移=%dms 误差<=%dms RTT=%dms", targetTime.In(constants.CST).Format("2006-01-02 15:04:05.000"), triggerTime.In(constants.CST).Format("2006-01-02 15:04:05.000"), serverTime.In(constants.CST).Format("2006-01-02 15:04:05.000"), calibration.Offset.Milliseconds(), calibration.ErrorBound.Milliseconds(), - calibration.RTT.Milliseconds(), - time.Now().Add(warmupRemain).In(constants.CST).Format("15:04:05.000")) + calibration.RTT.Milliseconds()) } }