func main()

in cmd/updater/main.go [166:246]


func main() {
	opt := gatherOptions()
	if err := opt.validate(); err != nil {
		logrus.Fatalf("Invalid flags: %v", err)
	}
	if !opt.confirm {
		logrus.Warning("--confirm=false (DRY-RUN): will not write to gcs")
	}
	switch {
	case opt.trace:
		logrus.SetLevel(logrus.TraceLevel)
	case opt.debug:
		logrus.SetLevel(logrus.DebugLevel)
	}

	if opt.jsonLogs {
		logrus.SetFormatter(&logrus.JSONFormatter{})
	}
	logrus.SetReportCaller(true)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	storageClient, err := gcs.ClientWithCreds(ctx, opt.creds)
	if err != nil {
		logrus.WithError(err).Fatal("Failed to create storage client")
	}
	defer storageClient.Close()

	client := gcs.NewClient(storageClient)

	log := logrus.WithFields(logrus.Fields{
		"group": opt.groupConcurrency,
		"build": opt.buildConcurrency,
	})
	log.Info("Configured concurrency")

	var rsClient *resultstore.DownloadClient
	if opt.enableResultStore {
		rsConn, err := resultstore.Connect(ctx, "")
		if err != nil {
			logrus.WithError(err).Fatal("Failed to connect to ResultStore.")
		}
		rsClient = resultstore.NewClient(rsConn)
	}

	updateGCS := updater.GCS(ctx, client, opt.groupTimeout, opt.buildTimeout, opt.buildConcurrency, opt.confirm, opt.enableIgnoreSkip)
	updateResultStore := resultstore.Updater(rsClient, client, opt.groupTimeout, opt.confirm)
	updateAll := updateGroup(updateGCS, updateResultStore)

	mets := updater.CreateMetrics(prometheus.NewFactory())

	pubsubClient, err := gpubsub.NewClient(ctx, gpubsub.DetectProjectID, option.WithCredentialsFile(opt.creds))
	if err != nil {
		logrus.WithError(err).Fatal("Failed to create pubsub client")
	}

	fixers := []updater.Fixer{
		updater.FixGCS(pubsub.NewClient(pubsubClient)),
	}

	if path := opt.persistQueue; path.String() != "" {
		const freq = time.Minute
		ticker := time.NewTicker(freq)
		log := logrus.WithField("frequency", freq)
		fixers = append(fixers, updater.FixPersistent(log, client, path, ticker.C))
	}

	opts := &updater.UpdateOptions{
		ConfigPath:       opt.config,
		GridPrefix:       opt.gridPrefix,
		GroupConcurrency: opt.groupConcurrency,
		GroupNames:       opt.groups.Strings(),
		Write:            opt.confirm,
		Freq:             opt.wait,
	}

	if err := updater.Update(ctx, client, mets, updateAll, opts, fixers...); err != nil {
		logrus.WithError(err).Error("Could not update")
	}
}