-
Notifications
You must be signed in to change notification settings - Fork 2
/
send-pr-build-job.go
62 lines (52 loc) · 1.21 KB
/
send-pr-build-job.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
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"errors"
"fmt"
"os"
"strings"
"google.golang.org/grpc"
"github.com/marwan-at-work/baghdad"
pb "github.com/marwan-at-work/baghdad/services"
"github.com/marwan-at-work/baghdad/worker"
)
func sendPRBuildJob(ctx context.Context, bj baghdad.BuildJob, w *worker.Worker, ch buildCh, logger *worker.Logger) (err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
numServices := 0
addr := os.Getenv("BUILDER_ADDR")
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
err = fmt.Errorf("could not connect to service builder service: %v", err)
return
}
defer conn.Close()
c := pb.NewServiceBuilderClient(conn)
respCh := make(chan buildResp)
for _, s := range bj.Baghdad.Services {
if s.IsExternal {
continue
}
numServices++
go buildService(ctx, c, bj, s, respCh)
}
errs := []error{}
for i := 0; i < numServices; i++ {
if br := <-respCh; br.err != nil {
cancel()
errs = append(errs, br.err)
}
}
ss := []string{}
for _, e := range errs {
if err != nil {
ss = append(ss, e.Error())
}
}
errMsg := strings.Join(ss, "\n")
if len(errs) > 0 {
return errors.New(errMsg)
}
logger.Loglnf("successfully built %v", bj.PRNum)
return
}