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

@@ -52,6 +52,10 @@ func GetWorkflowPeerIDs(wfID string, req *tools.APIRequest) ([]string, error) {
// Planner subscriptions
// ---------------------------------------------------------------------------
func SubscribeSessionConfirmation(executionsID string) (<-chan struct{}, func()) {
return execution.SubscribeSessionConfirmation(executionsID)
}
func SubscribePlannerUpdates(peerIDs []string) (<-chan string, func()) {
return planner.GetPlannerService().SubscribePlannerUpdates(peerIDs...)
}

View File

@@ -24,6 +24,46 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
)
// ---------------------------------------------------------------------------
// Session confirmation pub/sub
// ---------------------------------------------------------------------------
var sessionConfirmMu sync.Mutex
var sessionConfirmSubs = map[string][]chan struct{}{}
// SubscribeSessionConfirmation returns a channel that receives one signal when
// the first execution of the given session is fully confirmed (IsDraft=false).
// The returned cancel func must be called to clean up.
func SubscribeSessionConfirmation(executionsID string) (<-chan struct{}, func()) {
ch := make(chan struct{}, 1)
sessionConfirmMu.Lock()
sessionConfirmSubs[executionsID] = append(sessionConfirmSubs[executionsID], ch)
sessionConfirmMu.Unlock()
return ch, func() {
sessionConfirmMu.Lock()
subs := sessionConfirmSubs[executionsID]
for i, c := range subs {
if c == ch {
sessionConfirmSubs[executionsID] = append(subs[:i], subs[i+1:]...)
break
}
}
sessionConfirmMu.Unlock()
}
}
func notifySessionConfirmed(executionsID string) {
sessionConfirmMu.Lock()
subs := sessionConfirmSubs[executionsID]
sessionConfirmMu.Unlock()
for _, ch := range subs {
select {
case ch <- struct{}{}:
default:
}
}
}
// ---------------------------------------------------------------------------
// Global execution lock registry
// ---------------------------------------------------------------------------
@@ -135,6 +175,7 @@ func UpdateExecutionState(payload []byte, dt tools.DataType) {
return
}
if allConfirmed {
go notifySessionConfirmed(exec.ExecutionsID)
go confirmSessionOrder(exec.ExecutionsID, adminReq)
obj, _, err := workflow.NewAccessor(adminReq).LoadOne(exec.WorkflowID)
if err == nil && obj != nil {