-
Notifications
You must be signed in to change notification settings - Fork 30
/
additional_agents.go
45 lines (35 loc) · 1.05 KB
/
additional_agents.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
package server
import (
"context"
"sync"
"github.com/choria-io/go-choria/choria"
"github.com/choria-io/go-choria/server/agents"
"github.com/sirupsen/logrus"
)
// AgentInitializer is a function signature for a function that can register an agent
type AgentInitializer func(context.Context, *agents.Manager, choria.InstanceConnector, *logrus.Entry) error
var additionalAgents []AgentInitializer
var aamu *sync.Mutex
func init() {
additionalAgents = []AgentInitializer{}
aamu = &sync.Mutex{}
}
// RegisterAdditionalAgent adds an agent to a running server
// this should be used for compile time injection of agents
// other than the ones that ship with choria
func RegisterAdditionalAgent(i AgentInitializer) {
aamu.Lock()
defer aamu.Unlock()
additionalAgents = append(additionalAgents, i)
}
func (srv *Instance) setupAdditionalAgents(ctx context.Context) error {
aamu.Lock()
defer aamu.Unlock()
for _, initializer := range additionalAgents {
err := initializer(ctx, srv.agents, srv.connector, srv.log)
if err != nil {
return err
}
}
return nil
}