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
This commit is contained in:
@@ -176,6 +176,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
stepReads.bounds, stepReads.findings = func() jetstream.KeyValue { return pubBoundsKV.KV() }, found
|
||||
pubs := &publishes{bounds: pubBoundsKV.KV, versions: numberer.Versions, findings: found, bound: versions.PublishBound, logf: logger.Printf}
|
||||
numberer.Publishing = pubs.arm
|
||||
stepExpiry := &buildrun.Expiry{}
|
||||
var b *build.Builder
|
||||
seatsChanged := func(ctx context.Context) {
|
||||
heard.Watch(seats.Modules())
|
||||
@@ -186,8 +187,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
b = &build.Builder{
|
||||
Claimer: build.Claimer{Store: kvStore{buildsKV}, By: cred.Node + "." + cred.Module},
|
||||
Seats: seats,
|
||||
Asks: buildrun.Asker{Seats: seats, Publisher: asks, Waiter: buildrun.LostAskWaiter{Inner: heard, Dead: dead, Hearing: hearing}, Bound: bound, Dropper: buildrun.SeatDrops{Caller: calls}},
|
||||
Held: heldOnTheBus{js: js, seats: seats},
|
||||
Asks: buildrun.Asker{Seats: seats, Publisher: asks, Waiter: buildrun.LostAskWaiter{Inner: heard, Dead: dead, Hearing: hearing}, Bound: bound, Dropper: buildrun.SeatDrops{Caller: calls},
|
||||
Bounds: &stepBounds{bounds: pubBoundsKV.KV, now: time.Now, logf: logger.Printf}, Expiry: stepExpiry},
|
||||
Held: heldOnTheBus{js: js, seats: seats},
|
||||
// An ask that can no longer be answered is asked again (issue 1945), read at the step bound: a context's bound.
|
||||
Gone: heldOnTheBus{js: js, seats: seats},
|
||||
CheckAfter: bound,
|
||||
@@ -463,6 +465,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
unput.expired(ctx, e)
|
||||
return
|
||||
}
|
||||
if buildrun.StepBoundOf(e.Key()) {
|
||||
if e.Operation() == jetstream.KeyValuePurge { // its time to live ended: the ask's wait ends
|
||||
stepExpiry.Ended(e.Key())
|
||||
}
|
||||
return
|
||||
}
|
||||
if _, _, ok := versions.StepsBoundOf(e.Key()); ok {
|
||||
stepReads.expired(ctx, e)
|
||||
return
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user