From 2e620469c661145eb69a02ab381364839c4903f2 Mon Sep 17 00:00:00 2001 From: equanox Date: Thu, 8 Dec 2022 15:41:01 +0100 Subject: [PATCH] use optimized tasks --- bob/playbook/play.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bob/playbook/play.go b/bob/playbook/play.go index 751c9538..a0783505 100644 --- a/bob/playbook/play.go +++ b/bob/playbook/play.go @@ -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) { @@ -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() @@ -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 } @@ -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 {