feat: 优化代理准备并完善远端部署
- 增加严格代理、两分钟预取、白名单去重与分组状态展示\n- 增加远端注册令牌和安全地址校验\n- 增加 Docker Compose、Caddy 示例与控制中心部署文档
This commit is contained in:
@@ -48,7 +48,7 @@ func (s *Scheduler) ScheduleRun(req types.SeckillRequest) (types.ScheduleResult,
|
||||
|
||||
proxyCfg := s.proxySettings()
|
||||
|
||||
if proxyCfg.enabled && proxyCfg.autoFetchOnTimer && proxyCfg.proxyAPI != "" {
|
||||
if shouldPrepareProxyOnSchedule(proxyCfg) {
|
||||
proxyFetchRemain := triggerTime.Sub(serverTime) - proxyFetchBeforeTrigger
|
||||
if proxyFetchRemain < 0 {
|
||||
proxyFetchRemain = 0
|
||||
@@ -58,8 +58,10 @@ func (s *Scheduler) ScheduleRun(req types.SeckillRequest) (types.ScheduleResult,
|
||||
if s.IsRunning() {
|
||||
return
|
||||
}
|
||||
logger.LogEvent("代理", "info", "定时任务触发前,自动提取并校验分组代理...")
|
||||
if err := s.prepareProxyGroups(ap, true); err != nil {
|
||||
deadline := triggerTime.Add(-proxyReadyDeadline)
|
||||
logger.LogEvent("代理", "info", "定时任务触发前 2 分钟,开始提取并校验分组代理,截止=%s",
|
||||
deadline.In(constants.CST).Format("15:04:05.000"))
|
||||
if err := s.prepareProxyGroupsUntil(ap, true, deadline); err != nil {
|
||||
logger.LogEvent("代理", "error", "定时分组代理准备失败: %v", err)
|
||||
return
|
||||
}
|
||||
@@ -120,6 +122,13 @@ func (s *Scheduler) ScheduleRun(req types.SeckillRequest) (types.ScheduleResult,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func shouldPrepareProxyOnSchedule(cfg proxySettingsSnapshot) bool {
|
||||
if !cfg.enabled {
|
||||
return false
|
||||
}
|
||||
return cfg.required || (cfg.autoFetchOnTimer && cfg.proxyAPI != "")
|
||||
}
|
||||
|
||||
func (s *Scheduler) scheduleTimers(accountProducts map[string]string, targetTime, triggerTime time.Time, calibration types.TimeCalibration, attempts, delayMs int, resync bool) {
|
||||
serverTime := calibration.EstimatedServerNow()
|
||||
remain := triggerTime.Sub(serverTime)
|
||||
@@ -154,6 +163,10 @@ func (s *Scheduler) scheduleTimers(accountProducts map[string]string, targetTime
|
||||
estimatedServer.In(constants.CST).Format("15:04:05.000"),
|
||||
calibration.Offset.Milliseconds(),
|
||||
calibration.ErrorBound.Milliseconds())
|
||||
if ok, reason := s.ProxyRunGate(); !ok {
|
||||
logger.LogEvent("代理", "error", "严格代理模式未就绪,本次定时抢购不启动: %s", reason)
|
||||
return
|
||||
}
|
||||
if !s.TryStartRun() {
|
||||
logger.LogEvent("抢购", "warn", "已有抢购任务正在运行,本次定时触发已跳过")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user