fix(syb): retry drifting sync page once (#270)

This commit is contained in:
QiuSW
2026-09-12 09:34:44 +08:00
parent c24e8a4439
commit 8293b27c19
+18
View File
@@ -285,6 +285,24 @@ func loadDailyList(ctx context.Context, client *sybclient.Client, date string, p
if pageCount != len(page) {
return nil, fmt.Errorf("%s 货运单列表第 %d 页响应条数不自洽:total=%d,list=%d", date, pageIndex, pageCount, len(page))
}
// SYB may change a page while the list is being read. Re-read once
// before treating a boundary-page count drift as a fatal snapshot error.
if len(page) != expectedPageCount {
pause := time.NewTimer(500 * time.Millisecond)
select {
case <-ctx.Done():
pause.Stop()
return nil, ctx.Err()
case <-pause.C:
}
page, pageCount, err = client.ListPage(ctx, date, date, start, pageIndex, pageSize)
if err != nil {
return nil, fmt.Errorf("重读 %s 货运单列表第 %d 页失败:%w", date, pageIndex, err)
}
if pageCount != len(page) {
return nil, fmt.Errorf("%s 货运单列表第 %d 页重读响应条数不自洽:total=%d,list=%d", date, pageIndex, pageCount, len(page))
}
}
// Validate the whole page first: a same-page duplicate must not be
// hidden behind an earlier, recoverable cross-page overlap.
pageSeen := make(map[int64]int, len(page))