github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/cmd/jujud/agent/machine/apiworkers.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package machine 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/api" 10 "github.com/juju/juju/worker" 11 "github.com/juju/juju/worker/dependency" 12 ) 13 14 // APIWorkersConfig provides the dependencies for the 15 // apiworkers manifold. 16 type APIWorkersConfig struct { 17 APICallerName string 18 StartAPIWorkers func(api.Connection) (worker.Worker, error) 19 } 20 21 // APIWorkersManifold starts workers that rely on an API connection 22 // using a function provided to it. 23 // 24 // This manifold exists to start API workers which have not yet been 25 // ported to work directly with the dependency engine. Once all API 26 // workers started by StartAPIWorkers have been migrated to the 27 // dependency engine, this manifold can be removed. 28 func APIWorkersManifold(config APIWorkersConfig) dependency.Manifold { 29 return dependency.Manifold{ 30 Inputs: []string{ 31 config.APICallerName, 32 }, 33 Start: func(context dependency.Context) (worker.Worker, error) { 34 if config.StartAPIWorkers == nil { 35 return nil, errors.New("StartAPIWorkers not specified") 36 } 37 38 // Get API connection. 39 var apiConn api.Connection 40 if err := context.Get(config.APICallerName, &apiConn); err != nil { 41 return nil, err 42 } 43 return config.StartAPIWorkers(apiConn) 44 }, 45 } 46 }