Confirmation + Controlling API add
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user