package activator import ( "errors" "github.com/carlosframework/platform/internal/hostfiles" "time" ) // ServingFilesMissing preserves the ordinary no-evidence refusal while // giving diagnostics a host-incarnation key. It is not a retry policy. type ServingFilesMissing struct{ Incarnation string } func (e *ServingFilesMissing) Error() string { return hostfiles.ErrNoEvidence.Error() } func (e *ServingFilesMissing) Unwrap() error { return hostfiles.ErrNoEvidence } type seedDiagnostic struct { incarnation string at map[string]time.Time } func (a *Service) allowFilesDiagnostic(host string, err error, channel string) bool { var missing *ServingFilesMissing if !errors.As(err, &missing) { return true } a.mu.Lock() defer a.mu.Unlock() if a.seedDiagnostics == nil { a.seedDiagnostics = map[string]*seedDiagnostic{} } d := a.seedDiagnostics[host] if d == nil || d.incarnation != missing.Incarnation { d = &seedDiagnostic{incarnation: missing.Incarnation, at: map[string]time.Time{}} a.seedDiagnostics[host] = d } return a.allowFilesDiagnosticLocked(d, channel) } func (a *Service) allowFilesDiagnosticLocked(d *seedDiagnostic, channel string) bool { if d == nil { return true } now := time.Now() if a.now != nil { now = a.now() } if at := d.at[channel]; !at.IsZero() && now.Before(at.Add(time.Minute)) { return false } d.at[channel] = now return true }