in src/statequery/jobs.go [28:62]
func (state *State) RetrieveJobs(ctx context.Context) error {
// Create shared BQ client
client, err := bigquerySDK.NewService(ctx)
if err != nil {
log.Printf("failed to initialize BigQuery client: %v\n", err)
}
for _, reservation := range state.Reservations {
// Create sync & comms for concurrent invokations
ch := make(chan Job)
var wg sync.WaitGroup
wg.Add(len(reservation.Projects))
// Retrieve job stats for each assigned project
for _, project := range reservation.Projects {
// Create a per-project routine to avoid blocking on I/O during API calls
go retrieveJobsProject(ctx, client, project, reservation, ch, &wg)
}
go func() {
// Synchronize routines and close channel
wg.Wait()
close(ch)
}()
// Read found job stats into state
for job := range ch {
reservation.Jobs = append(reservation.Jobs, job)
}
id := fmt.Sprintf("%s.%s", reservation.Location, reservation.Name)
state.Reservations[id] = reservation
}
return nil
}