Skip to content

Commit

Permalink
use optimized tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Equanox committed Dec 8, 2022
1 parent e147119 commit 2e62046
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions bob/playbook/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"errors"
"fmt"
"time"

"github.com/benchkram/bob/pkg/boberror"
"github.com/benchkram/bob/pkg/usererror"
)

func (p *Playbook) Play() (err error) {
Expand All @@ -18,6 +15,15 @@ func (p *Playbook) play() error {
if p.done {
return ErrDone
}
p.oncePrepareOptimizedAccess.Do(func() {
_ = p.Tasks.walk(p.root, func(taskname string, task *Status, _ error) error {
for _, dependentTaskName := range task.DependsOn {
t := p.Tasks[dependentTaskName]
task.DependsOnIDs = append(task.DependsOnIDs, t.TaskID)
}
return nil
})
})

p.playMutex.Lock()
defer p.playMutex.Unlock()
Expand All @@ -32,7 +38,7 @@ func (p *Playbook) play() error {
// Once it returns `nil` the playbook is done with it's work.
var taskQueued = fmt.Errorf("task queued")
var taskFailed = fmt.Errorf("task failed")
err := p.Tasks.walk(p.root, func(taskname string, task *Status, err error) error {
err := p.TasksOptimized.walk(p.rootID, func(taskID int, task *Status, err error) error {
if err != nil {
return err
}
Expand All @@ -42,12 +48,8 @@ func (p *Playbook) play() error {
switch task.State() {
case StatePending:
// Check if all dependent tasks are completed
for _, dependentTaskName := range task.Task.DependsOn {
t, ok := p.Tasks[dependentTaskName]
if !ok {
//fmt.Printf("Task %s does not exist", dependentTaskName)
return usererror.Wrap(boberror.ErrTaskDoesNotExistF(dependentTaskName))
}
for _, dependentTaskID := range task.Task.DependsOnIDs {
t := p.TasksOptimized[dependentTaskID]

state := t.State()
if state != StateCompleted && state != StateNoRebuildRequired {
Expand Down

0 comments on commit 2e62046

Please sign in to comment.