| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package executor
- import (
- "sync"
- fw "git.buran.team/main/fairwind"
- )
- type ParallelChecker struct {
- global *Global
- ticket *Ticket
- checks []Check
- }
- func NewParallelChecker(global *Global, ticket *Ticket, checks []Check) (*ParallelChecker, error) {
- return &ParallelChecker{
- global: global,
- ticket: ticket,
- checks: checks,
- }, nil
- }
- func (this *ParallelChecker) Check() *TaskResult {
- this.global.Log.Debug("beginning checks parallel", fw.LogValue("uuid", this.ticket.UUID))
- defer this.global.Log.Debug("parallel checks ended", fw.LogValue("uuid", this.ticket.UUID))
- var mutex sync.Mutex
- report := map[string]CheckResult{}
- var waitGroup sync.WaitGroup
- waitGroup.Add(len(this.checks))
- for _, check := range this.checks {
- go func(check Check) {
- defer waitGroup.Done()
- result := check.Check()
- mutex.Lock()
- report[check.ID()] = result
- mutex.Unlock()
- }(check)
- }
- waitGroup.Wait()
- return NewTaskResultSuccess(report)
- }
|