Skip to content

Commit

Permalink
Re-added dependency loop detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann Gnaucke committed Apr 27, 2022
1 parent 9ae0b46 commit 730e456
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/duties/dutymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (dm *DutyManager) runTasks(dryRun bool) error {
if len(taskToBeDone) > 0 {
//tasksRunInThisWave gets incremented for every task that enters preflight or execution during this iteration
tasksRunInThisWave := 0
//tasksDoingSomething indicates how many tasks are currently running in the background
//This needs to be done before we increment tasksRunInThisWave in order to ensure a task doesn't finish in the delta between increment and checking if tasks are running
tasksDoingSomething := len(tasksDoingSomething(tl))

for i := range taskToBeDone {
task := taskToBeDone[i]
Expand All @@ -84,9 +87,12 @@ func (dm *DutyManager) runTasks(dryRun bool) error {
}

//If one of the tasks dependencies failed, we can't execute this task
if k.status.State == TaskStateFailed || k.status.State == TaskStatePreFlightFailed {
if k.status.State == TaskStateFailed || k.status.State == TaskStatePreFlightFailed || k.status.State == TaskStateDependencyFailed {
task.setStatus(TaskStateDependencyFailed)
task.status.Error = ErrDependencyFailed

//Avoid dependency loop detection
tasksRunInThisWave++
break
}
}
Expand Down Expand Up @@ -114,6 +120,12 @@ func (dm *DutyManager) runTasks(dryRun bool) error {
}
}

//Check if we are stuck (loop dependencies or something like that)
if tasksRunInThisWave == 0 && tasksDoingSomething == 0 {
logError("Executing failed because of dependency loop", ErrDependencyLoop)
return ErrDependencyLoop
}

} else {
//Check if there as still tasks running
//Block current thread until we successfully processed all tasks
Expand Down

0 comments on commit 730e456

Please sign in to comment.