Skip to content

Instantly share code, notes, and snippets.

@thrawn01
Created February 22, 2023 20:47
Show Gist options
  • Save thrawn01/2e8fcc33686c01fc5372b919b5070a58 to your computer and use it in GitHub Desktop.
Save thrawn01/2e8fcc33686c01fc5372b919b5070a58 to your computer and use it in GitHub Desktop.
// Distribute takes the slice of IonosUsers and distributes export jobs. Any errors during export are collected
// into the Supervisor's errorMap. This will return a ErrExportHadFailures error if any AppIDs failed to export
func (s *Supervisor) Distribute(ctx context.Context, exportUsers []IonosUser) error {
pool := conc.NewWithResults[int64]().WithMaxGoroutines(s.numWorkers).WithErrors().WithContext(ctx)
for _, user := range exportUsers {
pool.Go(func(c context.Context) (int64, error) {
err := s.ExportAppID(c, user)
if err != nil {
// To allow for recovery file creation
s.AddError(user.AppID, err)
}
return user.AppID, err
})
}
processed, err := pool.Wait()
if len(processed) != len(exportUsers) {
return fmt.Errorf("Missing AppIDs processed. Processed %d, expected %d", len(processed), len(exportUsers))
}
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment