Skip to content

Commit

Permalink
Wait for the Runs to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed May 5, 2020
1 parent fa95821 commit 12c2f0c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dkron/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dkron

import (
"fmt"
"sync"

"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -38,9 +39,13 @@ func (a *Agent) Run(jobName string, ex *Execution) (*Job, error) {
}

log.WithField("nodes", filterMap).Debug("agent: Filtered nodes to run")

var wg sync.WaitGroup
for _, v := range filterMap {
// Call here client GRPC AgentRun
go func(node string) {
wg.Add(1)
go func(node string, wg *sync.WaitGroup) {
defer wg.Done()
log.WithFields(logrus.Fields{
"job_name": job.Name,
"node": node,
Expand All @@ -53,8 +58,9 @@ func (a *Agent) Run(jobName string, ex *Execution) (*Job, error) {
"node": node,
}).Error("agent: Error calling AgentRun")
}
}(v)
}(v, &wg)
}

wg.Wait()
return job, nil
}

0 comments on commit 12c2f0c

Please sign in to comment.