-
Notifications
You must be signed in to change notification settings - Fork 405
/
static_pool.go
58 lines (50 loc) · 1.5 KB
/
static_pool.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
package agent
import (
"context"
"crypto/tls"
pool "github.com/fnproject/fn/api/runnerpool"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
// manages a single set of runners ignoring lb groups
type staticRunnerPool struct {
runners []pool.Runner
}
func DefaultStaticRunnerPool(runnerAddresses []string) pool.RunnerPool {
return NewStaticRunnerPool(runnerAddresses, nil)
}
func NewStaticRunnerPool(runnerAddresses []string, tlsConf *tls.Config, dialOpts ...grpc.DialOption) pool.RunnerPool {
logrus.WithField("runners", runnerAddresses).Info("Starting static runner pool")
var runners []pool.Runner
for _, addr := range runnerAddresses {
r, err := NewgRPCRunner(addr, tlsConf, dialOpts...)
if err != nil {
logrus.WithError(err).WithField("runner_addr", addr).Warn("Invalid runner")
continue
}
logrus.WithField("runner_addr", addr).Debug("Adding runner to pool")
runners = append(runners, r)
}
return &staticRunnerPool{
runners: runners,
}
}
func (rp *staticRunnerPool) Runners(ctx context.Context, call pool.RunnerCall) ([]pool.Runner, error) {
r := make([]pool.Runner, len(rp.runners))
copy(r, rp.runners)
return r, nil
}
func (rp *staticRunnerPool) Shutdown(ctx context.Context) error {
var retErr error
for _, r := range rp.runners {
err := r.Close(ctx)
if err != nil {
logrus.WithError(err).WithField("runner_addr", r.Address()).Error("Error closing runner")
// grab the first error only for now.
if retErr == nil {
retErr = err
}
}
}
return retErr
}