forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.go
36 lines (30 loc) · 1021 Bytes
/
agent.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
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package engine
import (
"github.com/juju/worker/v3"
"github.com/juju/worker/v3/dependency"
"github.com/juju/juju/agent"
)
// Some manifolds just depend on an agent; this type configures them.
type AgentManifoldConfig struct {
AgentName string
}
// AgentStartFunc encapsulates the behaviour that varies among AgentManifolds.
type AgentStartFunc func(agent.Agent) (worker.Worker, error)
// AgentManifold returns a dependency.Manifold that calls the supplied start
// func with the agent resource defined in the config (once it's present).
func AgentManifold(config AgentManifoldConfig, start AgentStartFunc) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.AgentName,
},
Start: func(context dependency.Context) (worker.Worker, error) {
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
return start(agent)
},
}
}