修复 WS Token 主动轮换与自动化任务恢复
根据服务端过期时间提前轮换 WS Token,并对缺失期限使用保守刷新窗口。 Token 获取瞬时失败时保持账号运行并在过期前持续重试;统一 Cookie、WS 恢复后的自动化唤醒和安全动作游标重试。 修复多实例恢复租约覆盖、规则查询误隔离及人工核对状态落库错误,并等待自动化调度器、续期 watcher 和批量发布恢复任务优雅退出。 补充 SQLite、PostgreSQL 17、生命周期和竞态回归测试。
This commit is contained in:
1 parent
9c742f5e7f
commit
bdc64c68f6
24 files changed
+1080
-110
No files matched your search
@@ -350,7 +350,6 @@ func (a *Adapter) FetchOrderDetail(ctx context.Context, cookieID, orderID, itemI
|
||||
if !a.OnPasswordLoginRefresh(ctx, cookieID) {
|
||||
return nil, fmt.Errorf("订单详情 Session 过期且即时续期失败: %w", err)
|
||||
}
|
||||
a.wakeCredentialBlockedAutomation(ctx, cookieID)
|
||||
a.logger.Info("Cookie 即时续期成功,重新请求订单详情", "account", cookieID, "order_id", orderID)
|
||||
return a.fetchOrderDetailAttempt(ctx, cookieID, orderID)
|
||||
}
|
||||
@@ -401,6 +400,7 @@ func (a *Adapter) fetchOrderDetailAttempt(ctx context.Context, cookieID, orderID
|
||||
fetchErr = errors.Join(fetchErr, fmt.Errorf("保存订单详情响应 Cookie: %w", persistErr))
|
||||
} else {
|
||||
cookieStr = authoritativeCookies
|
||||
a.wakeCredentialBlockedAutomation(ctx, cookieID)
|
||||
}
|
||||
}
|
||||
if fetchErr != nil {
|
||||
@@ -414,6 +414,7 @@ func (a *Adapter) fetchOrderDetailAttempt(ctx context.Context, cookieID, orderID
|
||||
if err := a.store.Cookies.UpdateRenewalCookie(ctx, cookieID, detail.UpdatedCookies, metadata, time.Now().Unix()); err != nil {
|
||||
return nil, fmt.Errorf("保存订单详情响应 Cookie: %w", err)
|
||||
}
|
||||
a.wakeCredentialBlockedAutomation(ctx, cookieID)
|
||||
}
|
||||
return &automation.OrderDetail{
|
||||
Quantity: detail.Quantity, SpecName: detail.SpecName, SpecValue: detail.SpecValue,
|
||||
@@ -477,6 +478,7 @@ func (a *Adapter) OnPasswordLoginRefresh(ctx context.Context, cookieID string) b
|
||||
|
||||
renewed, renewErr := a.tryProtocolCredentialRenew(ctx, d)
|
||||
if renewed {
|
||||
a.wakeCredentialBlockedAutomation(ctx, cookieID)
|
||||
a.recordPasswordLogin(ctx, cookieID, d.UserID, "success", "", "Go 协议续期成功")
|
||||
return true
|
||||
}
|
||||
@@ -490,6 +492,21 @@ func (a *Adapter) OnPasswordLoginRefresh(ctx context.Context, cookieID string) b
|
||||
return false
|
||||
}
|
||||
|
||||
// RecoverExpiredCredential 供自动化外部动作在平台明确拒绝旧 Session 后恢复凭证。
|
||||
func (a *Adapter) RecoverExpiredCredential(ctx context.Context, cookieID string) bool {
|
||||
return a.OnPasswordLoginRefresh(ctx, cookieID)
|
||||
}
|
||||
|
||||
// OnCredentialUpdated 接收账号运行时保存的新凭证并唤醒失败任务。
|
||||
func (a *Adapter) OnCredentialUpdated(ctx context.Context, cookieID string) {
|
||||
a.wakeCredentialBlockedAutomation(ctx, cookieID)
|
||||
}
|
||||
|
||||
// OnTransportReady 在 WS 注册完成后立即唤醒发送前明确未执行的任务。
|
||||
func (a *Adapter) OnTransportReady(ctx context.Context, cookieID string) {
|
||||
a.wakeCredentialBlockedAutomation(ctx, cookieID)
|
||||
}
|
||||
|
||||
func (a *Adapter) beginPasswordLogin(cookieID string) bool {
|
||||
a.passwordMu.Lock()
|
||||
defer a.passwordMu.Unlock()
|
||||
|
||||
Reference in new issue
Block a user