这是indexloc提供的服务,不要输入任何密码
Skip to content

Switch task graph edges to direct dependencies #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions cli/internal/core/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Scheduler struct {
TaskGraph *dag.AcyclicGraph
// Tasks are a map of tasks in the scheduler
Tasks map[string]*Task
taskDeps [][]string
PackageTaskDeps [][]string
}

Expand All @@ -39,7 +38,6 @@ func NewScheduler(topologicalGraph *dag.AcyclicGraph) *Scheduler {
TopologicGraph: topologicalGraph,
TaskGraph: &dag.AcyclicGraph{},
PackageTaskDeps: [][]string{},
taskDeps: [][]string{},
}
}

Expand Down Expand Up @@ -109,8 +107,6 @@ func (p *Scheduler) generateTaskGraph(scope []string, taskNames []string, tasksO

packageTasksDepsMap := getPackageTaskDepsMap(p.PackageTaskDeps)

taskDeps := [][]string{}

traversalQueue := []string{}

for _, pkg := range scope {
Expand Down Expand Up @@ -157,17 +153,11 @@ func (p *Scheduler) generateTaskGraph(scope []string, taskNames []string, tasksO
}

if hasTopoDeps {
depPkgs := p.TopologicGraph.DownEdges(pkg)
for _, from := range task.TopoDeps.UnsafeListOfStrings() {
// TODO: this should move out of the loop???
depPkgs, err := p.TopologicGraph.Ancestors(pkg)
if err != nil {
return fmt.Errorf("error getting ancestors: %w", err)
}

// add task dep from all the package deps within repo
for _, depPkg := range depPkgs.List() {
for depPkg := range depPkgs {
fromTaskId := util.GetTaskId(depPkg, from)
taskDeps = append(taskDeps, []string{fromTaskId, toTaskId})
p.TaskGraph.Add(fromTaskId)
p.TaskGraph.Add(toTaskId)
p.TaskGraph.Connect(dag.BasicEdge(toTaskId, fromTaskId))
Expand All @@ -179,7 +169,6 @@ func (p *Scheduler) generateTaskGraph(scope []string, taskNames []string, tasksO
if hasDeps {
for _, from := range deps.UnsafeListOfStrings() {
fromTaskId := util.GetTaskId(pkg, from)
taskDeps = append(taskDeps, []string{fromTaskId, toTaskId})
p.TaskGraph.Add(fromTaskId)
p.TaskGraph.Add(toTaskId)
p.TaskGraph.Connect(dag.BasicEdge(toTaskId, fromTaskId))
Expand All @@ -190,7 +179,6 @@ func (p *Scheduler) generateTaskGraph(scope []string, taskNames []string, tasksO
if hasPackageTaskDeps {
if pkgTaskDeps, ok := packageTasksDepsMap[toTaskId]; ok {
for _, fromTaskId := range pkgTaskDeps {
taskDeps = append(taskDeps, []string{fromTaskId, toTaskId})
p.TaskGraph.Add(fromTaskId)
p.TaskGraph.Add(toTaskId)
p.TaskGraph.Connect(dag.BasicEdge(toTaskId, fromTaskId))
Expand All @@ -200,16 +188,12 @@ func (p *Scheduler) generateTaskGraph(scope []string, taskNames []string, tasksO
}

if !hasDeps && !hasTopoDeps && !hasPackageTaskDeps {
// TODO: this should change to ROOT_NODE_NAME
fromTaskId := util.GetTaskId(pkg, "")
taskDeps = append(taskDeps, []string{fromTaskId, toTaskId})
p.TaskGraph.Add(ROOT_NODE_NAME)
p.TaskGraph.Add(toTaskId)
p.TaskGraph.Connect(dag.BasicEdge(toTaskId, ROOT_NODE_NAME))
}
}
}
p.taskDeps = taskDeps
return nil
}

Expand Down