feat: enforce durable queue resource limits and backpressure
This commit is contained in:
@@ -153,8 +153,15 @@ func (s *ScheduleStore) tickOne(ctx context.Context, ns, id, queue core.ID) (int
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
backpressured := false
|
||||
for _, decision := range batch.Decisions {
|
||||
if err := s.saveOccurrence(ctx, tx, v, version, decision, now); err != nil {
|
||||
if errors.Is(err, fault.QueueFull) {
|
||||
// 已提交本批较早的决定仍保留;满额的原触发点留待下次按冻结策略处理。
|
||||
t := decision.ScheduledAt
|
||||
next, backpressured = &t, true
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
if decision.Kind == "SKIPPED" {
|
||||
@@ -163,7 +170,9 @@ func (s *ScheduleStore) tickOne(ctx context.Context, ns, id, queue core.ID) (int
|
||||
fired++
|
||||
}
|
||||
}
|
||||
next = batch.Next
|
||||
if !backpressured {
|
||||
next = batch.Next
|
||||
}
|
||||
if next == nil && cursor < v.CurrentVersion {
|
||||
cursor++
|
||||
needsInitialization = true
|
||||
@@ -205,6 +214,9 @@ func (s *ScheduleStore) saveOccurrence(ctx context.Context, tx *sql.Tx, v schedu
|
||||
if in.QueueID != v.QueueID {
|
||||
return errors.New("schedule template queue mismatch")
|
||||
}
|
||||
if err := reserveQueueTask(ctx, tx, v.NamespaceID, v.QueueID); err != nil {
|
||||
return err
|
||||
}
|
||||
policy, err := json.Marshal(in.Retry)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user