fix(worker): 防止事务泄漏并恢复滞留队列

为 PostgreSQL 连接增加可配置的事务空闲与锁等待超时,并在请求取消或 Worker 退出后使用独立有界上下文回滚事务。\n\n恢复过期任务时按批次使用 SKIP LOCKED,周期重建缺失或终态 River Job;锁等待超时只在确认尚未提交上游时安全重排,避免重复执行和重复结算。\n\n验证:完整 Go 测试、go vet、生产 Kustomize 渲染、gofmt 与 git diff --check 均通过。
This commit is contained in:
2026-07-30 17:27:11 +08:00
parent bc44af751e
commit 6bab0f0749
32 changed files with 545 additions and 106 deletions
@@ -78,7 +78,7 @@ func (s *Store) ApplyOIDCTenantBindingSync(ctx context.Context, bindingID string
if err != nil {
return err
}
defer func() { _ = tx.Rollback(ctx) }()
defer rollbackTransaction(tx)
if unchanged {
tag, err := tx.Exec(ctx, `UPDATE gateway_oidc_tenant_bindings
SET last_sync_at=$2::timestamptz,next_sync_at=$2::timestamptz+interval '15 minutes',sync_failure_count=0,
@@ -129,7 +129,7 @@ func (s *Store) RejectOIDCTenantBinding(ctx context.Context, bindingID, category
if err != nil {
return err
}
defer func() { _ = tx.Rollback(ctx) }()
defer rollbackTransaction(tx)
tag, err := tx.Exec(ctx, `UPDATE gateway_oidc_tenant_bindings
SET access_status='disabled',metadata_status='rejected',last_sync_at=$2::timestamptz,
next_sync_at=$2::timestamptz+interval '15 minutes',