-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_pusher.go
50 lines (41 loc) · 1.06 KB
/
app_pusher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package cf_command
//go:generate counterfeiter -o ../fakes/push_cli_adapter.go --fake-name PushCLIAdapter . pushCLIAdapter
type pushCLIAdapter interface {
Push(name, directory, manifestFile string) error
}
//go:generate counterfeiter -o ../fakes/manifest_generator.go --fake-name ManifestGenerator . manifestGenerator
type manifestGenerator interface {
Generate(manifestStruct interface{}) (string, error)
}
type AppPusher struct {
Applications []Application
Adapter pushCLIAdapter
Concurrency int
ManifestPath string
Directory string
}
type Application struct {
Name string
}
func (a *AppPusher) Push() error {
sem := make(chan bool, a.Concurrency)
errs := make(chan error, len(a.Applications))
for _, app := range a.Applications {
sem <- true
go func(o Application, m string) {
defer func() { <-sem }()
err := a.Adapter.Push(o.Name, a.Directory, m)
if err != nil {
errs <- err
}
}(app, a.ManifestPath)
}
for i := 0; i < cap(sem); i++ {
sem <- true
}
close(errs)
if err := <-errs; err != nil {
return err
}
return nil
}