mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-17 01:00:09 -05:00
Add blocking_children to LeafNodeUpdated event
This commit is contained in:
@@ -231,6 +231,10 @@ func (e *DashboardExecutionTree) ChildCompleteChan() chan dashboardtypes.Dashboa
|
||||
// ChildStatusChanged implements DashboardParent
|
||||
func (*DashboardExecutionTree) ChildStatusChanged(context.Context) {}
|
||||
|
||||
func (*DashboardExecutionTree) GetBlockingDescendants() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *DashboardExecutionTree) Cancel() {
|
||||
// if we have not completed, and already have a cancel function - cancel
|
||||
if e.GetRunStatus() != dashboardtypes.RunInitialized || e.cancel == nil {
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
|
||||
type DashboardParentImpl struct {
|
||||
DashboardTreeRunImpl
|
||||
// are we blocked by a child run
|
||||
BlockingChildren []string `json:"blocking_children,omitempty"`
|
||||
children []dashboardtypes.DashboardTreeRun
|
||||
childCompleteChan chan dashboardtypes.DashboardTreeRun
|
||||
// are we blocked by a child run
|
||||
blockedByChild bool
|
||||
childStatusLock sync.Mutex
|
||||
childStatusLock sync.Mutex
|
||||
}
|
||||
|
||||
func (r *DashboardParentImpl) initialiseChildren(ctx context.Context) error {
|
||||
@@ -112,9 +112,9 @@ func (r *DashboardParentImpl) ChildStatusChanged(ctx context.Context) {
|
||||
|
||||
// if we are currently blocked by a child or we are currently in running state,
|
||||
// call setRunning() to determine whether any of our children are now blocked
|
||||
if r.blockedByChild || r.GetRunStatus() == dashboardtypes.RunRunning {
|
||||
if len(r.BlockingChildren) > 0 || r.GetRunStatus() == dashboardtypes.RunRunning {
|
||||
|
||||
log.Printf("[WARN] %s ChildStatusChanged - calling setRunning to see if we are still running, status %s blockedByChild %v", r.Name, r.GetRunStatus(), r.blockedByChild)
|
||||
log.Printf("[TRACE] %s ChildStatusChanged - calling setRunning to see if we are still running, status %s len(blockedByChildren) %d", r.Name, r.GetRunStatus(), len(r.BlockingChildren))
|
||||
|
||||
// try setting our status to running again
|
||||
r.setRunning(ctx)
|
||||
@@ -128,21 +128,34 @@ func (r *DashboardParentImpl) setRunning(ctx context.Context) {
|
||||
// and if so set our status to blocked
|
||||
|
||||
// if any children are blocked, we are blocked
|
||||
prevBlockingChildrenCount := len(r.BlockingChildren)
|
||||
r.BlockingChildren = nil
|
||||
for _, c := range r.children {
|
||||
if c.GetRunStatus() == dashboardtypes.RunBlocked {
|
||||
if p, ok := c.(dashboardtypes.DashboardParent); ok {
|
||||
r.BlockingChildren = append(r.BlockingChildren, p.GetBlockingDescendants()...)
|
||||
} else {
|
||||
r.BlockingChildren = append(r.BlockingChildren, c.GetName())
|
||||
}
|
||||
status = dashboardtypes.RunBlocked
|
||||
r.blockedByChild = true
|
||||
break
|
||||
}
|
||||
// to get here, no children can be blocked - clear blockedByChild
|
||||
r.blockedByChild = false
|
||||
}
|
||||
|
||||
// set status if it has changed
|
||||
if status != r.GetRunStatus() {
|
||||
log.Printf("[WARN] %s setRunning - setting state %s, blockedByChild %v", r.Name, status, r.blockedByChild)
|
||||
// set status if it has changed or if blocking children have changed
|
||||
if status != r.GetRunStatus() || prevBlockingChildrenCount != len(r.BlockingChildren) {
|
||||
log.Printf("[TRACE] %s setRunning - setting state %s, len(blockedByChildren) %d", r.Name, status, len(r.BlockingChildren))
|
||||
r.DashboardTreeRunImpl.setStatus(ctx, status)
|
||||
} else {
|
||||
log.Printf("[WARN] %s setRunning - state unchanged %s, blockedByChild %v", r.Name, status, r.blockedByChild)
|
||||
log.Printf("[TRACE] %s setRunning - state unchanged %s, len(blockedByChildren) %d", r.Name, status, len(r.BlockingChildren))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *DashboardParentImpl) GetBlockingDescendants() []string {
|
||||
if r.GetRunStatus() != dashboardtypes.RunBlocked {
|
||||
return nil
|
||||
}
|
||||
if len(r.BlockingChildren) == 0 {
|
||||
return []string{r.Name}
|
||||
}
|
||||
return r.BlockingChildren
|
||||
}
|
||||
|
||||
@@ -149,6 +149,8 @@ func (s *Server) HandleDashboardEvent(event dashboardevents.DashboardEvent) {
|
||||
s.writePayloadToSession(e.Session, payload)
|
||||
|
||||
case *dashboardevents.LeafNodeUpdated:
|
||||
log.Printf("[TRACE] LeafNodeUpdated %s status %s, blocking children %v", e.LeafNode["name"], e.LeafNode["status"], e.LeafNode["blocking_children"])
|
||||
|
||||
payload, payloadError = buildLeafNodeUpdatedPayload(e)
|
||||
if payloadError != nil {
|
||||
return
|
||||
|
||||
@@ -10,4 +10,5 @@ type DashboardParent interface {
|
||||
GetChildren() []DashboardTreeRun
|
||||
ChildrenComplete() bool
|
||||
ChildStatusChanged(context.Context)
|
||||
GetBlockingDescendants() []string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user