Skip to content

Commit

Permalink
Merge pull request #91 from cmars/chore/simplify-scraper-run
Browse files Browse the repository at this point in the history
chore: simplify scraper.Run
  • Loading branch information
cmars committed Dec 6, 2021
2 parents 406e244 + 420fea3 commit 0b22dbd
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions vervet-underground/internal/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io/ioutil"
"net/http"
"net/url"
"sync"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -101,24 +100,19 @@ func Clock(c func() time.Time) Option {
// Run executes the OpenAPI version scraping on all configured services.
func (s *Scraper) Run(ctx context.Context) error {
scrapeTime := s.timeNow().UTC()
var wg sync.WaitGroup
errCh := make(chan error)
errCh := make(chan error, len(s.services))
for i := range s.services {
svc := s.services[i]
wg.Add(1)
go func() {
defer wg.Done()
errCh <- s.scrape(ctx, scrapeTime, svc)
}()
}
go func() {
wg.Wait()
close(errCh)
}()
var errs error
for err := range errCh {
for _ = range s.services {
err := <-errCh
errs = multierr.Append(errs, err)
}
close(errCh)
return errs
}

Expand Down

0 comments on commit 0b22dbd

Please sign in to comment.