feat: 为执行后端增加独立容量池
test / python (pull_request) Successful in 13s
test / shell (pull_request) Successful in 20s
test / go (pull_request) Successful in 5m54s

This commit is contained in:
2026-09-21 07:21:38 +00:00
parent d06845bc3c
commit fadc93a0bf
9 changed files with 245 additions and 21 deletions
+16 -2
View File
@@ -57,6 +57,11 @@ type Claims interface {
WaitClaimed(context.Context, string) error
}
type Admission interface {
Acquire(string) bool
Release(string)
}
// Message is the subset of jetstream.Msg needed by one reconciliation.
type Message interface {
Data() []byte
@@ -70,13 +75,14 @@ type Processor struct {
TrustDomain string
Accepter Accepter
Claims Claims
Admission Admission
RetryDelay time.Duration
ClaimTimeout time.Duration
}
func (p Processor) Process(ctx context.Context, message Message) error {
if p.Accepter == nil || p.Claims == nil {
return errors.New("assignment accepter and claim registry are required")
if p.Accepter == nil || p.Claims == nil || p.Admission == nil {
return errors.New("assignment accepter, claim registry, and backend admission pool are required")
}
assignment, err := taskassignment.Unmarshal(message.Data(), p.TrustDomain)
if err != nil {
@@ -85,8 +91,16 @@ func (p Processor) Process(ctx context.Context, message Message) error {
if _, err := p.Claims.Offer(assignment); err != nil {
return errors.Join(err, message.TermWithReason("conflicting assignment"))
}
if !p.Admission.Acquire(assignment.ID) {
delay := p.RetryDelay
if delay <= 0 {
delay = 2 * time.Second
}
return message.NakWithDelay(delay)
}
accepted, err := p.Accepter.Accept(ctx, assignment)
if err != nil {
p.Admission.Release(assignment.ID)
delay := p.RetryDelay
if delay <= 0 {
delay = 15 * time.Second