Skip to content

Commit

Permalink
chore: Parallel attestors per type.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Glastra <[email protected]>
  • Loading branch information
matglas committed May 3, 2024
1 parent c581572 commit f55352f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions attestation/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"crypto"
"fmt"
"os"
"sync"
"time"

"github.com/in-toto/go-witness/cryptoutil"
Expand Down Expand Up @@ -138,16 +139,27 @@ func (ctx *AttestationContext) RunAttestors() error {
order := runTypeOrder()
for _, k := range order {
log.Debugf("Starting %s attestors...", k.String())

var wg sync.WaitGroup
ch := make(chan int, len(attestors))

for _, att := range attestors[k] {
log.Infof("Starting %v attestor...", att.Name())
ctx.runAttestor(att)
wg.Add(1)
go func(att Attestor) {
defer func() { wg.Done(); <-ch }()
ctx.runAttestor(att)
}(att)
}
wg.Wait()
log.Infof("Completed %s attestors...", k.String())
}

return nil
}

func (ctx *AttestationContext) runAttestor(attestor Attestor) {
log.Infof("Starting %v attestor...", attestor.Name())

startTime := time.Now()
if err := attestor.Attest(ctx); err != nil {
ctx.completedAttestors = append(ctx.completedAttestors, CompletedAttestor{
Expand All @@ -171,6 +183,8 @@ func (ctx *AttestationContext) runAttestor(attestor Attestor) {
if producer, ok := attestor.(Producer); ok {
ctx.addProducts(producer)
}

log.Debugf("Finished %v attestor...", attestor.Name())
}

func (ctx *AttestationContext) CompletedAttestors() []CompletedAttestor {
Expand Down

0 comments on commit f55352f

Please sign in to comment.