Files
mesh-delivery/modules/mesh-delivery-watchman/internal/watch/mirror.go
T

43 lines
1.5 KiB
Go

package watch
import (
"git.novox.be/novox/mesh-sdk/go/delivery"
"time"
)
// A waiting ask is a move (novox/hq ADR 0525 §4, issue 1887 A8b): a message on a build seat's stream (mesh-sdk go/delivery
// AskStream) that a node of the seat must pull. Its pulse is the pulse of the bucket named as the stream, under the ask's id;
// the ask put on the seat is the move beginning at its time, and the ask taken (its step key `<node>.<ask id>` written in
// the build module's steps, delivery.StepsBucket) is the move done. An ask no node takes within the bound is stuck, as any
// move. The watchman reads no bucket of the controller for it.
// AskedKey names a waiting ask for the pulse and stuck keys: the seat's stream and the ask's id.
func askedBucket(language string) (string, error) { return delivery.AskStream(language) }
// Asked is an ask of a build seat of language put on its stream at time at (the ask's own time).
func (w *Watchman) Asked(language, id string, at time.Time) {
bucket, err := askedBucket(language)
if err != nil {
w.say("no pulse for the ask %s: %v", id, err)
return
}
w.mu.Lock()
defer w.mu.Unlock()
if at.IsZero() {
at = w.now()
}
w.mirror(bucket, id, describe("the ask %s to be taken by a node", id), "", at, 0)
}
// Taken is the ask taken by a node: its step key written. The pulse is deleted, so it never expires, and a stuck key it left is
// written as moved.
func (w *Watchman) Taken(language, id string) {
bucket, err := askedBucket(language)
if err != nil {
return
}
w.mu.Lock()
defer w.mu.Unlock()
w.moved(bucket, id)
}