Skip to content

Commit e20e03f

Browse files
committed
task graph: sprinkle comments and fix typos
1 parent adf0cf5 commit e20e03f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

pkg/payload/task_graph.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,15 @@ func FlattenByNumberAndComponent(tasks []*Task) [][]*TaskNode {
128128
return [][]*TaskNode{groups}
129129
}
130130

131+
// TaskNode represents a node in a TaskGraph. The node assumes the graph is indexable and nodes are retrievable by index,
132+
// and In/Out are indices of other nodes connected to this one by incoming/outgoing edges, respectively.
131133
type TaskNode struct {
132-
In []int
134+
// In is a list of node indices from which there is an edge to this node (=prerequisites)
135+
In []int
136+
// Tasks to be executed when this node is visited
133137
Tasks []*Task
134-
Out []int
138+
// Out is a list of node indices to which there is an edge from this node (=dependents).
139+
Out []int
135140
}
136141

137142
func (n TaskNode) String() string {
@@ -262,7 +267,7 @@ func (g *TaskGraph) Split(onFn func(task *Task) bool) {
262267
}
263268

264269
// BreakFunc returns the input tasks in order of dependencies with
265-
// explicit parallelizm allowed per task in an array of task nodes.
270+
// explicit parallelism allowed per task in an array of task nodes.
266271
type BreakFunc func([]*Task) [][]*TaskNode
267272

268273
// ShiftOrder rotates each TaskNode by step*len/stride when stride > len,
@@ -424,8 +429,8 @@ type taskStatus struct {
424429
}
425430

426431
// RunGraph executes the provided graph in order and in parallel up to maxParallelism. It will not start
427-
// a new TaskNode until all of the prerequisites have completed. If fn returns an error, no dependencies
428-
// of that node will be executed, but other indepedent edges will continue executing.
432+
// a new TaskNode until all its prerequisites have completed. If fn returns an error, no dependencies
433+
// of that node will be executed, but other independent edges will continue executing.
429434
func RunGraph(ctx context.Context, graph *TaskGraph, maxParallelism int, fn func(ctx context.Context, tasks []*Task) error) []error {
430435
submitted := make([]bool, len(graph.Nodes))
431436
results := make([]*taskStatus, len(graph.Nodes))
@@ -452,7 +457,7 @@ func RunGraph(ctx context.Context, graph *TaskGraph, maxParallelism int, fn func
452457
return -1
453458
}
454459

455-
// Tasks go out to the workers via workCh, and results come brack
460+
// Tasks go out to the workers via workCh, and results come back
456461
// from the workers via resultCh.
457462
workCh := make(chan runTasks, maxParallelism)
458463
defer close(workCh)

pkg/payload/task_graph_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ func TestRunGraph(t *testing.T) {
743743
{
744744
name: "nodes executed after dependencies",
745745
nodes: []*TaskNode{
746+
// In: prerequisites (by index)
747+
// Out: dependents (by index)
746748
{Tasks: tasks("c"), In: []int{3}},
747749
{Tasks: tasks("d", "e"), In: []int{3}},
748750
{Tasks: tasks("f"), In: []int{3}, Out: []int{4}},
@@ -773,6 +775,8 @@ func TestRunGraph(t *testing.T) {
773775
{
774776
name: "task error interrupts node processing",
775777
nodes: []*TaskNode{
778+
// In: prerequisites (by index)
779+
// Out: dependents (by index)
776780
{Tasks: tasks("c"), In: []int{2}},
777781
{Tasks: tasks("d"), In: []int{2}, Out: []int{3}},
778782
{Tasks: tasks("a", "b"), Out: []int{0, 1}},
@@ -799,6 +803,8 @@ func TestRunGraph(t *testing.T) {
799803
{
800804
name: "mid-task cancellation error interrupts node processing",
801805
nodes: []*TaskNode{
806+
// In: prerequisites (by index)
807+
// Out: dependents (by index)
802808
{Tasks: tasks("c"), In: []int{2}},
803809
{Tasks: tasks("d"), In: []int{2}, Out: []int{3}},
804810
{Tasks: tasks("a", "b"), Out: []int{0, 1}},
@@ -853,6 +859,8 @@ func TestRunGraph(t *testing.T) {
853859
{
854860
name: "task errors in parallel nodes both reported",
855861
nodes: []*TaskNode{
862+
// In: prerequisites (by index)
863+
// Out: dependents (by index)
856864
{Tasks: tasks("a"), Out: []int{1}},
857865
{Tasks: tasks("b"), In: []int{0}, Out: []int{2, 4, 8}},
858866
{Tasks: tasks("c1"), In: []int{1}, Out: []int{3}},
@@ -878,8 +886,10 @@ func TestRunGraph(t *testing.T) {
878886
wantErrs: []string{"error - c1", "error - f"},
879887
},
880888
{
881-
name: "cancelation without task errors is reported",
889+
name: "cancellation without task errors is reported",
882890
nodes: []*TaskNode{
891+
// In: prerequisites (by index)
892+
// Out: dependents (by index)
883893
{Tasks: tasks("a"), Out: []int{1}},
884894
{Tasks: tasks("b"), In: []int{0}},
885895
},

0 commit comments

Comments
 (0)