github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/jujud/agent/engine/agent.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package engine 5 6 import ( 7 "gopkg.in/juju/worker.v1" 8 "gopkg.in/juju/worker.v1/dependency" 9 10 "github.com/juju/juju/agent" 11 ) 12 13 // Some manifolds just depend on an agent; this type configures them. 14 type AgentManifoldConfig struct { 15 AgentName string 16 } 17 18 // AgentStartFunc encapsulates the behaviour that varies among AgentManifolds. 19 type AgentStartFunc func(agent.Agent) (worker.Worker, error) 20 21 // AgentManifold returns a dependency.Manifold that calls the supplied start 22 // func with the agent resource defined in the config (once it's present). 23 func AgentManifold(config AgentManifoldConfig, start AgentStartFunc) dependency.Manifold { 24 return dependency.Manifold{ 25 Inputs: []string{ 26 config.AgentName, 27 }, 28 Start: func(context dependency.Context) (worker.Worker, error) { 29 var agent agent.Agent 30 if err := context.Get(config.AgentName, &agent); err != nil { 31 return nil, err 32 } 33 return start(agent) 34 }, 35 } 36 }