WIRE, not delete: per-repo max_retries is a configured field with a real consumer (the retry gate), and it works for the legacy single-identity [[repos]] list. In a multi-identity deployment repositories live under [[identities.repos]] and there is no global [[repos]] at all, so the resolver never saw the override and a parked task was killed at the global cap rather than the configured one. MaxRetries now consults the identity named on the task before the legacy list, then falls back to the global cap. Identity name is the only thing that says which repository list owns a persisted row. Red-then-green: TestMaxRetriesResolvesFromTheOwningIdentity gained the multi-identity cases; "identity repo override wins over the global cap" failed with `MaxRetries = 3, want 7`. Two neighbouring cases keep the fix honest: another identity's override must not leak, and the legacy path must still resolve. Mutation-verified by deleting only the identity lookup, keeping the extracted helper and the API intact.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
// Package taskactions adapts legacy task persistence to operator actions.
|
|
package taskactions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
|
)
|
|
|
|
type Store struct{ storecontract.TaskStore }
|
|
|
|
func (s Store) TaskByID(ctx context.Context, id int64) (*taskactions.Task, error) {
|
|
t, err := s.TaskStore.TaskByID(ctx, id)
|
|
if err != nil || t == nil {
|
|
return nil, err
|
|
}
|
|
return &taskactions.Task{ID: t.ID, Owner: t.Owner, Repo: t.Repo, Identity: t.Identity, Status: t.Status, Stage: t.Stage, ParkReason: t.ParkReason, IssueNumber: t.IssueNumber, RetryCount: t.RetryCount, ForgeBacked: t.IsForgeBacked()}, nil
|
|
}
|
|
|
|
func MaxRetries(cfg *config.Holder) func(*taskactions.Task) int {
|
|
return func(t *taskactions.Task) int {
|
|
if cfg == nil {
|
|
return 0
|
|
}
|
|
c := cfg.Get()
|
|
// A multi-identity deployment declares its repositories under
|
|
// [[identities.repos]] and has no global [[repos]] at all, so the
|
|
// task's owning identity is the only place a per-repo override can
|
|
// live. Without this lookup the override is never matched and the
|
|
// task dies at the global cap instead of the configured one.
|
|
if t.Identity != "" {
|
|
for _, identity := range c.Identities {
|
|
if identity.Name != t.Identity {
|
|
continue
|
|
}
|
|
if n, ok := repoMaxRetries(identity.Repos, t, c.MaxRetries); ok {
|
|
return n
|
|
}
|
|
break
|
|
}
|
|
}
|
|
if n, ok := repoMaxRetries(c.Repos, t, c.MaxRetries); ok {
|
|
return n
|
|
}
|
|
return c.MaxRetries
|
|
}
|
|
}
|
|
|
|
// repoMaxRetries returns the effective cap for the task's repository within one
|
|
// repository list, and whether that list knows the repository at all.
|
|
func repoMaxRetries(repos []config.Repo, t *taskactions.Task, global int) (int, bool) {
|
|
for _, repo := range repos {
|
|
if repo.Owner == t.Owner && repo.Name == t.Repo {
|
|
return repo.EffectiveMaxRetries(global), true
|
|
}
|
|
}
|
|
return 0, false
|
|
}
|