fix: 停复机指令队列审查问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m24s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m24s
- 开关开启但分发器心跳缺失时回退为当场执行,避免指令无人消费 - 待确认指令先查上游状态再判断;执行期间被覆盖时把待确认带到新指令 - 同方向失败退避中重复写入不提前执行时间 - 领取容量把执行上限与本秒剩余 QPS 分开计算 - 队列复机共用单卡复机锁;执行上下文取消后按结果未知确认 - 消费者并行停止;读取最近调用时间失败时不覆盖;成功但终结日志失败按成功处理 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,11 +56,12 @@ func (s *Store) WriteCommand(ctx context.Context, cmd StopResumeCommand) (int64,
|
||||
|
||||
// SRClaimInput 是一次账户停复机领取的参数。
|
||||
type SRClaimInput struct {
|
||||
CarrierID uint
|
||||
Lease time.Duration
|
||||
Capacity int // 执行上限与剩余 QPS 的较小值
|
||||
TokenPrefix string
|
||||
MinInterval time.Duration
|
||||
CarrierID uint
|
||||
Lease time.Duration
|
||||
InflightLimit int // 账户停复机执行上限(含执行中)
|
||||
Budget int // 停复机所在限流组本秒剩余;-1 表示不按 QPS 限制
|
||||
TokenPrefix string
|
||||
MinInterval time.Duration
|
||||
}
|
||||
|
||||
// SRClaimed 是一条被领取的停复机指令。
|
||||
@@ -76,7 +77,7 @@ type SRClaimed struct {
|
||||
func (s *Store) ClaimStopResume(ctx context.Context, input SRClaimInput) ([]SRClaimed, int64, error) {
|
||||
raw, err := srClaimScript.Run(ctx, s.redis,
|
||||
[]string{constants.RedisCarrierStopResumeQueueKey(input.CarrierID), constants.RedisCarrierStopResumeRunningKey(input.CarrierID)},
|
||||
time.Now().UnixMilli(), input.Lease.Milliseconds(), input.Capacity, input.TokenPrefix, input.MinInterval.Milliseconds(),
|
||||
time.Now().UnixMilli(), input.Lease.Milliseconds(), input.InflightLimit, input.TokenPrefix, input.MinInterval.Milliseconds(), input.Budget,
|
||||
).Slice()
|
||||
if err != nil || len(raw) == 0 {
|
||||
return nil, 0, err
|
||||
@@ -105,6 +106,7 @@ type SRFinish struct {
|
||||
Token string
|
||||
Version int64
|
||||
Done bool // true 结束并删除指令
|
||||
Unknown bool // 本次结果未知:版本已变大时把待确认带到新指令
|
||||
NextAt time.Time
|
||||
Set map[string]string
|
||||
Del []string
|
||||
@@ -121,7 +123,11 @@ func (s *Store) FinishStopResume(ctx context.Context, finish SRFinish) (int64, e
|
||||
if next.IsZero() || next.Before(now) {
|
||||
next = now
|
||||
}
|
||||
args := []any{finish.Token, finish.CardID, finish.Version, done, next.UnixMilli(), now.UnixMilli(), len(finish.Set)}
|
||||
unknown := "0"
|
||||
if finish.Unknown {
|
||||
unknown = "1"
|
||||
}
|
||||
args := []any{finish.Token, finish.CardID, finish.Version, done, next.UnixMilli(), now.UnixMilli(), unknown, len(finish.Set)}
|
||||
for field, value := range finish.Set {
|
||||
args = append(args, field, value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user