Files
mesh-catalog/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/checktime.go
T

35 lines
1.1 KiB
Go

package main
import "time"
// lastCheckTime is how long the newest answered check of a repository ran, as its verdict says it (`took`): the
// repository's last measured check time (novox/hq ADR 0505 §4). Zero when no verdict of the repository says it.
// Under the lock.
func (h *Holder) lastCheckTime(repository string) time.Duration {
var newest *Verdict
var took time.Duration
for _, d := range h.deliveries {
v := d.Check
if d.Repository != repository || v == nil || v.Took == "" {
continue
}
t, err := time.ParseDuration(v.Took)
if err != nil || t <= 0 {
continue
}
if newest == nil || v.At.After(newest.At) {
newest, took = v, t
}
}
return took
}
// answeredRefusalBound is how long a refusal the gate is already answering waits before it is said as stalled: twice
// the repository's last measured check time, at least the floor (ADR 0505 §4). Under the lock.
func (h *Holder) answeredRefusalBound(repository string) time.Duration {
if b := 2 * h.lastCheckTime(repository); b > h.refusalFloor() {
return b
}
return h.refusalFloor()
}