S8 unread-away: Unread of a state and a view, the away answers, the start's phase

Builds: design 47 H2 H-A-708 (1) (2), H-A-717 (DQ-54, DQ-58)
This commit is contained in:
2026-11-25 17:09:15 +01:00
parent b4f9429115
commit f0bc6a3ceb
11 changed files with 294 additions and 6 deletions
+41
View File
@@ -77,6 +77,8 @@ type ProcessReader struct {
unheard int
lastUnheard string
startedAt time.Time
// phase is the phase the holder's start is in, nil while none runs (BeginPhase).
phase *StartPhase
// hooked is the hub the count of unhandled events is wired on, so a second Start counts no event twice.
hooked *process.EventHub
}
@@ -939,6 +941,7 @@ func (r *ProcessReader) Start(ctx context.Context, js jetstream.JetStream, cred
if status != nil {
status.Ready(func(kv jetstream.KeyValue) {
KeepOwnBuild(ctx, kv, process.OwnBuild(), r.logf)
r.keepPhase()
if err := hearAgain(ctx, kv, r.Followers, r.logf); err != nil {
r.logf("views: the hand asks of %s's first views are not heard (%v) until it starts again", r.Module, err)
}
@@ -952,6 +955,44 @@ func (r *ProcessReader) Start(ctx context.Context, js jetstream.JetStream, cred
r.Ask(ctx, said)
}
// BeginPhase says the holder's start is in the phase name since now, ending the one before: it is said in the journal and
// kept at StartPhaseKey of the state `first-views`, which the part's first-views tool answers beside the views, so a call
// that meets `away` while the holder starts says what the start is doing (design 47 H2 H-A-708 (1), H-A-717 DQ-54). EndPhase
// ends it.
func (r *ProcessReader) BeginPhase(name string) {
r.mu.Lock()
r.phase = &StartPhase{Name: name, Since: r.now().UTC()}
r.mu.Unlock()
r.logf("views: %s's start is in the phase %s", r.Module, name)
r.keepPhase()
}
// EndPhase says the holder's start is in no phase.
func (r *ProcessReader) EndPhase() {
r.mu.Lock()
ended := r.phase
r.phase = nil
r.mu.Unlock()
if ended != nil {
r.logf("views: %s's start ends the phase %s", r.Module, ended.Name)
}
r.keepPhase()
}
// keepPhase writes the phase now at StartPhaseKey, once the state is there (a bucket not yet opened keeps it for then).
func (r *ProcessReader) keepPhase() {
r.mu.Lock()
status, phase := r.status, r.phase
r.mu.Unlock()
if status == nil {
return
}
data, _ := json.Marshal(phase)
if _, err := status.Put(context.Background(), StartPhaseKey, data); err != nil {
r.logf("views: the start phase is not kept in %s: %v", StatusState, err)
}
}
// handleEvent registers handle on the hub for a seat's event on its bare subject and on every further part after it
// (`<subject>.>`): one handler, both forms, as the seat's contract says the event on either (design 47 H, H-A-166; one
// subscription per event, design 47 G §532). The two patterns do not overlap, so a message reaches the handler once.