@@ -139,7 +139,7 @@ type TaskNode struct {
139
139
Out []int
140
140
}
141
141
142
- func (n TaskNode ) String () string {
142
+ func (n * TaskNode ) String () string {
143
143
var arr []string
144
144
for _ , t := range n .Tasks {
145
145
if len (t .Manifest .OriginalFilename ) > 0 {
@@ -474,16 +474,16 @@ func RunGraph(ctx context.Context, graph *TaskGraph, maxParallelism int, fn func
474
474
}
475
475
for i := 0 ; i < maxParallelism ; i ++ {
476
476
wg .Add (1 )
477
- go func (ctx context.Context , job int ) {
477
+ go func (ctx context.Context , worker int ) {
478
478
defer utilruntime .HandleCrash ()
479
479
defer wg .Done ()
480
480
for {
481
481
select {
482
482
case <- ctx .Done ():
483
- klog .V (2 ).Infof ("Canceled worker %d while waiting for work" , job )
483
+ klog .V (2 ).Infof ("Worker %d: Received cancel signal while waiting for work" , worker )
484
484
return
485
485
case runTask := <- workCh :
486
- klog .V (2 ).Infof ("Running %d on worker %d" , runTask .index , job )
486
+ klog .V (2 ).Infof ("Worker %d: Running job %d (with %d tasks) " , worker , runTask .index , len ( runTask . tasks ) )
487
487
err := fn (ctx , runTask .tasks )
488
488
resultCh <- taskStatus {index : runTask .index , error : err }
489
489
}
@@ -492,9 +492,10 @@ func RunGraph(ctx context.Context, graph *TaskGraph, maxParallelism int, fn func
492
492
}
493
493
494
494
var inflight int
495
- nextNode := getNextNode ()
496
- done := false
495
+ var done bool
496
+
497
497
for ! done {
498
+ nextNode := getNextNode ()
498
499
switch {
499
500
case ctx .Err () == nil && nextNode >= 0 : // push a task or collect a result
500
501
select {
@@ -522,18 +523,16 @@ func RunGraph(ctx context.Context, graph *TaskGraph, maxParallelism int, fn func
522
523
default : // no work to push and nothing in flight. We're done
523
524
done = true
524
525
}
525
- if ! done {
526
- nextNode = getNextNode ()
527
- }
528
526
}
529
527
530
528
cancelFn ()
531
529
wg .Wait ()
532
- klog .V (2 ).Infof ("Workers finished" )
530
+ klog .V (2 ).Info ("Workers finished" )
533
531
534
532
var errs []error
535
533
var firstIncompleteNode * TaskNode
536
- incompleteCount := 0
534
+ var incompleteCount int
535
+
537
536
for i , result := range results {
538
537
if result == nil {
539
538
if firstIncompleteNode == nil && len (graph .Nodes [i ].Tasks ) > 0 {
@@ -552,9 +551,6 @@ func RunGraph(ctx context.Context, graph *TaskGraph, maxParallelism int, fn func
552
551
}
553
552
}
554
553
555
- klog .V (2 ).Infof ("Result of work: %v" , errs )
556
- if len (errs ) > 0 {
557
- return errs
558
- }
559
- return nil
554
+ klog .V (2 ).Infof ("Result of work: errs=%v" , errs )
555
+ return errs
560
556
}
0 commit comments