Skip to content

Commit

Permalink
A little Refactoring log reader.
Browse files Browse the repository at this point in the history
changes are following.

1. Start taskIndex from 1
2. Remove importing package ```"sync/atomic"```
3. Reduce copying count on Reader object
  • Loading branch information
16yuki0702 authored and tekton-robot committed Feb 28, 2020
1 parent a39a267 commit 1f7ed8a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/helper/log/pipeline_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package log
import (
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/tektoncd/cli/pkg/helper/pipelinerun"
Expand Down Expand Up @@ -53,21 +52,22 @@ func (r *Reader) readLivePipelineLogs(pr *v1alpha1.PipelineRun) (<-chan Log, <-c
trC := prTracker.Monitor(r.tasks)

wg := sync.WaitGroup{}
taskIndex := int32(1)
taskIndex := 0

for trs := range trC {
wg.Add(len(trs))

for _, run := range trs {
taskIndex++
// NOTE: passing tr, taskIdx to avoid data race
go func(tr trh.Run, taskNum int32) {
go func(tr trh.Run, taskNum int) {
defer wg.Done()

// clone the object to keep task number and name separately
c := r.clone()
c.setUpTask(int(taskNum), tr)
c.pipeLogs(logC, errC)
}(run, atomic.AddInt32(&taskIndex, 1))
}(run, taskIndex)
}
}

Expand Down Expand Up @@ -103,9 +103,9 @@ func (r *Reader) readAvailablePipelineLogs(pr *v1alpha1.PipelineRun) (<-chan Log
defer close(logC)
defer close(errC)

// clone the object to keep task number and name separately
c := r.clone()
for i, tr := range taskRuns {
// clone the object to keep task number and name separately
c := r.clone()
c.setUpTask(i+1, tr)
c.pipeLogs(logC, errC)
}
Expand Down

0 comments on commit 1f7ed8a

Please sign in to comment.