feat(seckill): 增加只读预演并强化代理风控切换

This commit is contained in:
yml
2026-11-22 14:52:46 +08:00
parent 70612a8f0c
commit e20907800d
20 changed files with 1916 additions and 40 deletions
+16 -2
View File
@@ -82,8 +82,11 @@ type Scheduler struct {
proxyRefillInFlight bool
proxyRefillRetryAt time.Time
proxyFallbackActive bool
paths types.AppPaths
font *truetype.Font
// proxyBusinessRiskVerified 表示当前活动代理池已逐组通过只读业务风控预检。
// 代理切换、配置变更或池重建后必须重新验证。
proxyBusinessRiskVerified bool
paths types.AppPaths
font *truetype.Font
successImages *image.SuccessImageSaver
@@ -150,6 +153,11 @@ type Scheduler struct {
calibrationMu sync.Mutex
calibrationOffsets []time.Duration // 最近N次校准偏移,用于中位数平滑
drillMu sync.Mutex
drillStatus types.SeckillDrillStatus
drillCancel chan struct{}
drillTrigger time.Time
}
// SetStateChangeCallback 设置运行状态变化回调。
@@ -212,6 +220,7 @@ func New(cli *client.DouyuClient, paths types.AppPaths, font *truetype.Font, con
// Close 关闭调度器的后台资源。
func (s *Scheduler) Close() {
s.CancelSeckillDrill()
s.closeAccountClients()
s.clientMu.Lock()
directClient := s.directClient
@@ -449,6 +458,7 @@ func (s *Scheduler) TryStartRun() bool {
s.proxyMonitor = make(chan struct{})
monitor := s.proxyMonitor
s.runMu.Unlock()
s.stopSeckillDrillForRealRun()
s.clientMu.RLock()
generation := s.proxyPoolGeneration
s.clientMu.RUnlock()
@@ -528,6 +538,7 @@ func (s *Scheduler) ProxyRunGateFor(accountProducts map[string]string) (bool, st
dirty := s.accountClientsDirty
expired := !s.accountClientsExpireAt.IsZero() &&
!time.Now().Before(s.accountClientsExpireAt.Add(-30*time.Second))
businessRiskVerified := s.proxyBusinessRiskVerified
hasFailedGroup := false
for _, group := range s.proxyGroups {
if group != nil && group.failed {
@@ -545,6 +556,9 @@ func (s *Scheduler) ProxyRunGateFor(accountProducts map[string]string) (bool, st
if hasFailedGroup {
return false, "代理池存在失败组,等待备用代理"
}
if !businessRiskVerified {
return false, "代理业务风控预检未完成或代理已切换"
}
names := selectedAccountNames(accountProducts)
if len(names) > 0 && !s.accountClientsCover(names) {
return false, "代理池未覆盖当前账号、已失效或存在失败组"