feat(proxy): 支持品赞分组代理与自动白名单
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"douyu_go/internal/client"
|
||||
"douyu_go/internal/constants"
|
||||
"douyu_go/internal/logger"
|
||||
"douyu_go/internal/types"
|
||||
@@ -47,12 +46,9 @@ 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()
|
||||
proxyCfg := s.proxySettings()
|
||||
|
||||
if autoFetch && apiURL != "" {
|
||||
if proxyCfg.enabled && proxyCfg.autoFetchOnTimer && proxyCfg.proxyAPI != "" {
|
||||
proxyFetchRemain := triggerTime.Sub(serverTime) - proxyFetchBeforeTrigger
|
||||
if proxyFetchRemain < 0 {
|
||||
proxyFetchRemain = 0
|
||||
@@ -62,20 +58,11 @@ func (s *Scheduler) ScheduleRun(req types.SeckillRequest) (types.ScheduleResult,
|
||||
if s.IsRunning() {
|
||||
return
|
||||
}
|
||||
logger.LogEvent("代理", "info", "定时任务触发前,自动从 API 提取最新独立代理...")
|
||||
res, err := client.FetchProxyFromAPI(apiURL)
|
||||
if err != nil {
|
||||
logger.LogEvent("代理", "warn", "定时自动提取代理失败: %v,继续使用现有网络通道", err)
|
||||
logger.LogEvent("代理", "info", "定时任务触发前,自动提取并校验分组代理...")
|
||||
if err := s.prepareProxyGroups(ap, true); err != nil {
|
||||
logger.LogEvent("代理", "error", "定时分组代理准备失败: %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()
|
||||
}
|
||||
@@ -202,7 +189,10 @@ func (s *Scheduler) CancelSchedule() bool {
|
||||
}
|
||||
|
||||
func (s *Scheduler) calibrateDouyuTime(label string) types.TimeCalibration {
|
||||
cli := s.clientSnapshot()
|
||||
cli := s.calibrationClient()
|
||||
if cli == nil {
|
||||
return types.TimeCalibration{Fallback: true}
|
||||
}
|
||||
calibration, err := cli.BestServerTimeCalibration(timeCalibrateRounds, timeCalibrateWait)
|
||||
if err != nil {
|
||||
logger.LogEvent("时间", "warn", "%s校准降级: %v", label, err)
|
||||
|
||||
Reference in New Issue
Block a user