Skip to content

Commit

Permalink
Use goroutine for sync (#2378)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdickman authored and dgageot committed Jul 1, 2019
1 parent e20185f commit f17c034
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/skaffold/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/bmatcuk/doublestar"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -150,6 +151,7 @@ func matchSyncRules(syncRules []*latest.SyncRule, relPath, containerWd string) (
}

func Perform(ctx context.Context, image string, files syncMap, cmdFn func(context.Context, v1.Pod, v1.Container, map[string][]string) []*exec.Cmd, namespaces []string) error {
errs, ctx := errgroup.WithContext(ctx)
if len(files) == 0 {
return nil
}
Expand All @@ -174,9 +176,10 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex

cmds := cmdFn(ctx, p, c, files)
for _, cmd := range cmds {
if _, err := util.RunCmdOut(cmd); err != nil {
errs.Go(func() error {
_, err := util.RunCmdOut(cmd)
return err
}
})
numSynced++
}
}
Expand All @@ -187,5 +190,5 @@ func Perform(ctx context.Context, image string, files syncMap, cmdFn func(contex
return errors.New("didn't sync any files")
}

return nil
return errs.Wait()
}

0 comments on commit f17c034

Please sign in to comment.