-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathconfig.go
39 lines (33 loc) · 1.3 KB
/
config.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
package plugins
import (
"os/exec"
"github.com/smartcontractkit/chainlink-relay/pkg/loop"
)
// RegistrarConfig generates contains static configuration inher
type RegistrarConfig interface {
RegisterLOOP(loopId string, cmdName string) (func() *exec.Cmd, loop.GRPCOpts, error)
}
type registarConfig struct {
grpcOpts loop.GRPCOpts
loopRegistrationFn func(loopId string) (*RegisteredLoop, error)
}
// NewRegistrarConfig creates a RegistarConfig
// loopRegistrationFn must act as a global registry function of LOOPs and must be idempotent.
// The [func() *exec.Cmd] for a LOOP should be generated by calling [RegistrarConfig.RegisterLOOP]
func NewRegistrarConfig(grpcOpts loop.GRPCOpts, loopRegistrationFn func(loopId string) (*RegisteredLoop, error)) RegistrarConfig {
return ®istarConfig{
grpcOpts: grpcOpts,
loopRegistrationFn: loopRegistrationFn,
}
}
// RegisterLOOP calls the configured loopRegistrationFn. The loopRegistrationFn must act as a global registry for LOOPs and must be idempotent.
func (pc *registarConfig) RegisterLOOP(loopID string, cmdName string) (func() *exec.Cmd, loop.GRPCOpts, error) {
cmdFn, err := NewCmdFactory(pc.loopRegistrationFn, CmdConfig{
ID: loopID,
Cmd: cmdName,
})
if err != nil {
return nil, loop.GRPCOpts{}, err
}
return cmdFn, pc.grpcOpts, nil
}