feat(proxy): 支持多实例独立代理与短效API动态提取
- 实例配置独立:支持为每个实例单独配置 http/https/socks5 代理,避免单机多开挤兑触发斗鱼出口 IP 限流 - 动态 API 提取:原生支持星空代理等平台的 API 提取(兼容 JSON/文本格式),提供前端一键提取填入与连通性/延迟测速 - 定时前自动拉取:针对 3 分钟短效代理,支持在开抢前 15 秒自动提取并绑定最新 IP,并在预热前完成热连接与时间复校 - 修复复校竞态:将 resyncBeforeTrigger 从 3s 提升至 8s,确保三轮采样在开抢前顺利落盘,消除时钟漂移 - 验证方式:通过 go test ./... 全量测试与前端 vue-tsc/vite 编译,实测通过星空代理 API 解析测试用例
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"douyu_go/internal/client"
|
||||
"douyu_go/internal/constants"
|
||||
"douyu_go/internal/logger"
|
||||
"douyu_go/internal/types"
|
||||
@@ -46,6 +47,39 @@ func (s *Scheduler) ScheduleRun(req types.SeckillRequest) (types.ScheduleResult,
|
||||
|
||||
s.scheduleTimers(ap, targetTime, triggerTime, calibration, req.Attempts, req.DelayMs, false)
|
||||
|
||||
s.proxyMu.RLock()
|
||||
autoFetch := s.autoFetchProxyOnSchedule
|
||||
apiURL := s.proxyAPI
|
||||
s.proxyMu.RUnlock()
|
||||
|
||||
if autoFetch && apiURL != "" {
|
||||
proxyFetchRemain := triggerTime.Sub(serverTime) - proxyFetchBeforeTrigger
|
||||
if proxyFetchRemain < 0 {
|
||||
proxyFetchRemain = 0
|
||||
}
|
||||
s.scheduleMu.Lock()
|
||||
s.replaceTimerLocked(&s.proxyFetchSchedule, proxyFetchRemain, func() {
|
||||
if s.IsRunning() {
|
||||
return
|
||||
}
|
||||
logger.LogEvent("代理", "info", "定时任务触发前,自动从 API 提取最新独立代理...")
|
||||
res, err := client.FetchProxyFromAPI(apiURL)
|
||||
if err != nil {
|
||||
logger.LogEvent("代理", "warn", "定时自动提取代理失败: %v,继续使用现有网络通道", err)
|
||||
return
|
||||
}
|
||||
cli := s.clientSnapshot()
|
||||
if cli != nil {
|
||||
if err := cli.SetProxy(res.ProxyURL); err != nil {
|
||||
logger.LogEvent("代理", "warn", "应用提取代理失败: %v", err)
|
||||
} else {
|
||||
logger.LogEvent("代理", "success", "定时自动应用最新代理: %s (IP=%s 归属=%s)", res.ProxyURL, res.IP, res.Region)
|
||||
}
|
||||
}
|
||||
})
|
||||
s.scheduleMu.Unlock()
|
||||
}
|
||||
|
||||
resyncRemain := triggerTime.Sub(serverTime) - resyncBeforeTrigger
|
||||
if resyncRemain < 0 {
|
||||
resyncRemain = 0
|
||||
@@ -213,4 +247,8 @@ func (s *Scheduler) stopSchedulesLocked() {
|
||||
s.resyncSchedule.Stop()
|
||||
s.resyncSchedule = nil
|
||||
}
|
||||
if s.proxyFetchSchedule != nil {
|
||||
s.proxyFetchSchedule.Stop()
|
||||
s.proxyFetchSchedule = nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user