Skip to content

Commit

Permalink
Fix topological_sort_by_dfs was discarded (?) in the Workflow con…
Browse files Browse the repository at this point in the history
…structor
  • Loading branch information
singularitti committed Nov 29, 2022
1 parent b6858d1 commit 2f9ead1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/workflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@ struct Workflow
@assert is_connected(graph) "`graph` must be connected!"
@assert nv(graph) == length(jobs) "`graph` has different size from `jobs`!"
@assert allunique(jobs) "at least two jobs are identical!"
return new(jobs, graph)
order = topological_sort_by_dfs(graph)
reordered_jobs = collect(jobs[order])
n = length(reordered_jobs)
new_graph = DiGraph(n)
dict = IdDict(zip(reordered_jobs, 1:n))
# You must sort the graph too for `DependentJob`s to run in the correct order!
for (i, job) in enumerate(reordered_jobs)
for parent in job.parents
if !has_edge(new_graph, dict[parent], i)
add_edge!(new_graph, dict[parent], i)
end
end
for child in job.children
if !has_edge(new_graph, i, dict[child])
add_edge!(new_graph, i, dict[child])
end
end
end
return new(reordered_jobs, new_graph)
end
end
"""
Expand Down

0 comments on commit 2f9ead1

Please sign in to comment.