()
| 35 | func (s ParallelScript) Exists() bool { return true } |
| 36 | |
| 37 | func (s ParallelScript) Run() error { |
| 38 | existingScripts := s.findExistingScripts(s.allScripts) |
| 39 | |
| 40 | s.logger.Info(s.logTag, "Will run %d %s scripts in parallel", len(existingScripts), s.name) |
| 41 | |
| 42 | resultsChan := make(chan scriptResult) |
| 43 | |
| 44 | for _, script := range existingScripts { |
| 45 | script := script |
| 46 | go func() { resultsChan <- scriptResult{script, script.Run()} }() |
| 47 | } |
| 48 | |
| 49 | var failedScripts, passedScripts []string |
| 50 | |
| 51 | for i := 0; i < len(existingScripts); i++ { |
| 52 | r := <-resultsChan |
| 53 | jobName := r.Script.Tag() |
| 54 | |
| 55 | if r.Error == nil { |
| 56 | passedScripts = append(passedScripts, jobName) |
| 57 | s.logger.Info(s.logTag, "'%s' script has successfully executed", r.Script.Path()) |
| 58 | } else { |
| 59 | failedScripts = append(failedScripts, jobName) |
| 60 | s.logger.Error(s.logTag, "'%s' script has failed with error: %s", r.Script.Path(), r.Error) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return s.summarizeErrs(passedScripts, failedScripts) |
| 65 | } |
| 66 | |
| 67 | func (s ParallelScript) Cancel() error { |
| 68 | s.logger.Debug(s.logTag, "Canceling a parallel script") |
no test coverage detected