[gitsync] Launch all watchers in parallel

This should help startup time, at least by not forcing all repos to wait
on some slow ones.

Bug: skia:10543
Change-Id: Ibe14ce961020d3914415ff46bd3ca09c44d567e5
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/306189
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Eric Boren <borenet@google.com>
diff --git a/gitsync/go/gitsync/main.go b/gitsync/go/gitsync/main.go
index 3f36582..781ad7d 100644
--- a/gitsync/go/gitsync/main.go
+++ b/gitsync/go/gitsync/main.go
@@ -18,6 +18,7 @@
 	"go.skia.org/infra/go/httputils"
 	"go.skia.org/infra/go/human"
 	"go.skia.org/infra/go/sklog"
+	"golang.org/x/sync/errgroup"
 )
 
 // This server watches a list of git repos for changes and syncs the meta data of all commits
@@ -125,8 +126,6 @@
 		}
 	}
 
-	// TODO(stephana): Pass the token source explicitly to the BigTable related functions below.
-
 	// Create token source.
 	ts, err := auth.NewDefaultTokenSource(false, auth.SCOPE_USERINFO_EMAIL, auth.SCOPE_GERRIT, pubsub.AUTH_SCOPE)
 	if err != nil {
@@ -135,10 +134,15 @@
 
 	// Start all repo watchers.
 	ctx := context.Background()
+	var egroup errgroup.Group
 	for _, repoURL := range config.RepoURLs {
-		if err := watcher.Start(ctx, btConfig, repoURL, gitilesURLs[repoURL], *gcsBucket, *gcsPath, time.Duration(config.RefreshInterval), ts); err != nil {
-			sklog.Fatalf("Error initializing repo watcher: %s", err)
-		}
+		repoURL := repoURL
+		egroup.Go(func() error {
+			return watcher.Start(ctx, btConfig, repoURL, gitilesURLs[repoURL], *gcsBucket, *gcsPath, time.Duration(config.RefreshInterval), ts)
+		})
+	}
+	if err := egroup.Wait(); err != nil {
+		sklog.Fatal(err)
 	}
 
 	// Set up the http handler to indicate ready-ness and start serving.