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