refactor(sniper): 对齐 dygou_go 调度架构,增加双时间日志并解耦预热
- 抢购调度重构:参考 dygou_go 将 sniper 拆分为独立子模块(runner/run_control/retry/exchange/classify/config/summary/category/helpers);移除全局自适应降速与轮次上限,采用账号独立循环、统一账号级退避、单请求并发闸门与首发错峰 - 预热与建连优化:默认关闭预热(避免单账号超时连坐整机开抢),开启时转为后台非阻塞协程;WebSocket 握手超时从 10s 降至 1500ms - 双时间日志:logger 增加 SetServerOffset,校准后日志前缀自动渲染「本地时间(H虎牙估算时间)」,实现跨机器绝对毫秒对齐 - 默认配置调优:版本提升至 v0.5.0,默认线程调为 2(缓解多实例并发限流),前端自动平滑迁移 - 验证方式:go test ./... -count=1 全通,npm run build 构建正常,单测覆盖双时间与预热配置
This commit is contained in:
@@ -198,3 +198,39 @@ func TestMinLevelFiltersDebug(t *testing.T) {
|
||||
t.Fatalf("LevelFromString(非法) = %q, want info", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDoubleTimeWithServerOffset 验证设置服务端时间偏移后,日志带双时间前缀。
|
||||
func TestDoubleTimeWithServerOffset(t *testing.T) {
|
||||
store, path, closeLog := initForTest(t)
|
||||
defer func() {
|
||||
SetServerOffset(0)
|
||||
closeLog()
|
||||
}()
|
||||
|
||||
// 模拟服务端比本地快 500ms
|
||||
SetServerOffset(500 * time.Millisecond)
|
||||
if ServerOffset() != 500*time.Millisecond {
|
||||
t.Fatalf("ServerOffset() = %v, want 500ms", ServerOffset())
|
||||
}
|
||||
|
||||
LogEvent("监控", LevelInfo, "双时间测试消息")
|
||||
closeLog()
|
||||
|
||||
entries := store.Since(0)
|
||||
if len(entries) == 0 {
|
||||
t.Fatal("未写入日志条目")
|
||||
}
|
||||
last := entries[len(entries)-1]
|
||||
if !strings.Contains(last.Time, "(H") {
|
||||
t.Fatalf("条目 Time 未包含虎牙估算时间前缀: %s", last.Time)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("读取日志文件失败: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(data), "(H") {
|
||||
t.Fatalf("文件未包含虎牙估算时间前缀:\n%s", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user