Confirmation + Controlling API add

This commit is contained in:
mr
2026-04-10 15:16:29 +02:00
parent da4d4bd546
commit 4b9b1b8b91
13 changed files with 116 additions and 17 deletions

View File

@@ -198,6 +198,10 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
schedulerMu.Unlock()
if updated.Confirm {
// Subscribe BEFORE calling Schedule to avoid missing the notification.
confirmCh, confirmUnsub := infrastructure.SubscribeSessionConfirmation(executionsID)
defer confirmUnsub()
workflowScheduler.UUID = executionsID
_, _, _, schedErr := infrastructure.Schedule(&workflowScheduler, wfID, req)
if schedErr != nil {
@@ -206,8 +210,23 @@ func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
})
return
}
fmt.Println("UPDATE CONFIRM — waiting for execution confirmation")
select {
case <-confirmCh:
_ = conn.WriteJSON(map[string]interface{}{
"confirmed": true,
"scheduling_id": executionsID,
})
case <-time.After(60 * time.Second):
_ = conn.WriteJSON(map[string]interface{}{
"confirmed": false,
"error": "confirmation timeout: scheduling accepted but peers did not confirm in time",
})
case <-ctx.Done():
// client disconnected before confirmation
}
confirmed = true
fmt.Println("UPDATE CONFIRM")
fmt.Println("UPDATE CONFIRM done")
return
}
// Detect mode change before updating local vars.