修复激进模式错误
This commit is contained in:
@@ -82,7 +82,7 @@ func defaultConfig() types.Config {
|
||||
Concurrency: constants.DefaultConcurrency,
|
||||
Attempts: constants.DefaultAttempts,
|
||||
RetryStages: defaultRetryStages(),
|
||||
SeckillMode: types.SeckillModeAggressive,
|
||||
SeckillMode: types.SeckillModeNormal,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -286,6 +286,10 @@ func (s *Scheduler) RunNow(accountProducts map[string]string) {
|
||||
// 激进模式每轮开始时清空缓存,强制重新获取 CSRF
|
||||
if s.seckillMode == types.SeckillModeAggressive {
|
||||
s.clearAttemptCache()
|
||||
// 第1轮时从预热数据初始化缓存
|
||||
if round == 1 {
|
||||
s.initCacheFromWarmup(roundAttempts)
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogEvent("抢购", "info", "第%d轮: 待抢购 %d 个账号,本轮执行=%d,剩余时间=%v,模式=%s",
|
||||
@@ -560,6 +564,20 @@ func (s *Scheduler) getAttemptCache(accountName string) *types.AttemptCache {
|
||||
return s.attemptCache[accountName]
|
||||
}
|
||||
|
||||
// initCacheFromWarmup 从预热数据初始化激进模式缓存。
|
||||
func (s *Scheduler) initCacheFromWarmup(attempts []types.ExchangeAttempt) {
|
||||
for _, attempt := range attempts {
|
||||
if warmup, ok := s.warmupFor(attempt); ok {
|
||||
s.setAttemptCache(attempt.Account.Name, &types.AttemptCache{
|
||||
CSRF: warmup.CSRF,
|
||||
RoleName: warmup.RoleName,
|
||||
LastCheck: time.Now(),
|
||||
})
|
||||
logger.LogEvent("抢购", "info", "从预热初始化缓存: 账号=%s", attempt.Account.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) setAttemptCache(accountName string, cache *types.AttemptCache) {
|
||||
s.attemptCacheMu.Lock()
|
||||
defer s.attemptCacheMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user