Created
February 22, 2023 20:47
-
-
Save thrawn01/2e8fcc33686c01fc5372b919b5070a58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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