Files
mesh-delivery/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/stepbounds.go
T
jschoubben eaa578a4b9 Builder: an ask's step bounds are keys with their own time to live
buildrun.Asker takes optional Bounds and Expiry: the stand-still bound and the cap of three bounds are
the keys stand.<ask> and cap.<ask> of the builder's state bounds, whose expiry the builder's watch of
that state tells the Expiry, and Wait ends then; no timer of the process. With no Bounds (the checker's
Asker, which the lead's A-118 leaves as it is) Wait keeps its timers.

Builds: design 47 G A-77, A-101, A-118
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 01:07:35 +01:00

43 lines
1.3 KiB
Go

package main
import (
"context"
"errors"
"fmt"
"time"
"github.com/nats-io/nats.go/jetstream"
"mesh-delivery-builder/internal/versions"
)
// stepBounds keeps the bounds of an ask's step as keys of the state bounds with their own time to live (design 47 G A-77, A-101,
// A-118): the bus's marker of a key's end, heard on the watch of the state, is told to buildrun.Asker's Expiry. No timer.
type stepBounds struct {
bounds func() jetstream.KeyValue
now func() time.Time
logf func(string, ...any)
}
// Arm is buildrun.StepBounds' Arm: the key is written afresh, so a step that moved has its bound counted from its movement.
func (s *stepBounds) Arm(ctx context.Context, key, why string, bound time.Duration) error {
kv := s.bounds()
if kv == nil {
return fmt.Errorf("%s is not on the bus yet", versions.BoundsBucket)
}
if err := kv.Delete(ctx, key); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
return err
}
_, err := kv.Create(ctx, key, versions.EncodeBound(why, s.now().Add(bound)), jetstream.KeyTTL(bound))
return err
}
// End is buildrun.StepBounds' End.
func (s *stepBounds) End(ctx context.Context, key string) {
if kv := s.bounds(); kv != nil {
if err := kv.Delete(ctx, key); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
s.logf("the step bound %s is not deleted: %v", key, err)
}
}
}