本文整理汇总了Golang中github.com/juju/juju/worker/dependency.Context.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Get方法的具体用法?Golang Context.Get怎么用?Golang Context.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/worker/dependency.Context
的用法示例。
在下文中一共展示了Context.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: start
// start is a StartFunc for a Worker manifold.
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
if err := config.validate(); err != nil {
return nil, errors.Trace(err)
}
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, errors.Trace(err)
}
facade, err := config.NewFacade(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
modelTag, err := apiCaller.ModelTag()
if err != nil {
return nil, errors.Trace(err)
}
worker, err := config.NewWorker(Config{
Facade: facade,
Model: modelTag.Id(),
Check: config.Check,
})
if err != nil {
return nil, errors.Trace(err)
}
return worker, nil
}
示例2: start
// start is a dependency.StartFunc that uses config.
func (config FlagManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
var gate Waiter
if err := context.Get(config.GateName, &gate); err != nil {
return nil, errors.Trace(err)
}
worker, err := config.NewWorker(gate)
if err != nil {
return nil, errors.Trace(err)
}
return worker, nil
}
示例3: start
func (mh *tracedManifoldHarness) start(context dependency.Context) (worker.Worker, error) {
for _, resourceName := range mh.inputs {
if err := context.Get(resourceName, nil); err != nil {
return nil, errors.Trace(err)
}
}
w := &minimalWorker{tomb.Tomb{}, mh.ignoreExternalKill}
go func() {
defer w.tomb.Done()
mh.starts <- struct{}{}
select {
case <-w.tombDying():
case err := <-mh.errors:
w.tomb.Kill(err)
}
}()
return w, nil
}
示例4: newStatusWorker
func newStatusWorker(config ManifoldConfig, context dependency.Context) (worker.Worker, error) {
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
tag := agent.CurrentConfig().Tag()
unitTag, ok := tag.(names.UnitTag)
if !ok {
return nil, errors.Errorf("expected unit tag, got %v", tag)
}
agentConfig := agent.CurrentConfig()
stateFile := NewStateFile(path.Join(agentConfig.DataDir(), "meter-status.yaml"))
runner := config.NewHookRunner(unitTag, config.MachineLockName, agentConfig, config.Clock)
// If we don't have a valid APICaller, start a meter status
// worker that works without an API connection.
var apiCaller base.APICaller
err := context.Get(config.APICallerName, &apiCaller)
if errors.Cause(err) == dependency.ErrMissing {
logger.Tracef("API caller dependency not available, starting isolated meter status worker.")
cfg := IsolatedConfig{
Runner: runner,
StateFile: stateFile,
Clock: config.Clock,
AmberGracePeriod: defaultAmberGracePeriod,
RedGracePeriod: defaultRedGracePeriod,
TriggerFactory: GetTriggers,
}
return config.NewIsolatedStatusWorker(cfg)
} else if err != nil {
return nil, err
}
logger.Tracef("Starting connected meter status worker.")
status := config.NewMeterStatusAPIClient(apiCaller, unitTag)
cfg := ConnectedConfig{
Runner: runner,
StateFile: stateFile,
Status: status,
}
return config.NewConnectedStatusWorker(cfg)
}
示例5: start
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
var apiCaller base.APICaller
if err := context.Get(config.APICallerName, &apiCaller); err != nil {
return nil, errors.Trace(err)
}
facade, err := config.NewFacade(apiCaller)
if err != nil {
return nil, errors.Trace(err)
}
worker, err := config.NewWorker(Config{
Facade: facade,
Entity: config.Entity,
Result: config.Result,
})
if err != nil {
return nil, errors.Trace(err)
}
return worker, nil
}
示例6: newCollect
func newCollect(config ManifoldConfig, context dependency.Context) (*collect, error) {
period := defaultPeriod
if config.Period != nil {
period = *config.Period
}
var agent agent.Agent
if err := context.Get(config.AgentName, &agent); err != nil {
return nil, err
}
var metricFactory spool.MetricFactory
err := context.Get(config.MetricSpoolName, &metricFactory)
if err != nil {
return nil, err
}
var charmdir fortress.Guest
err = context.Get(config.CharmDirName, &charmdir)
if err != nil {
return nil, err
}
agentConfig := agent.CurrentConfig()
tag := agentConfig.Tag()
unitTag, ok := tag.(names.UnitTag)
if !ok {
return nil, errors.Errorf("expected a unit tag, got %v", tag)
}
paths := uniter.NewWorkerPaths(agentConfig.DataDir(), unitTag, "metrics-collect")
runner := &hookRunner{
unitTag: unitTag.String(),
paths: paths,
}
var listener stopper
charmURL, validMetrics, err := readCharm(unitTag, paths)
if err != nil {
return nil, errors.Trace(err)
}
if len(validMetrics) > 0 && charmURL.Schema == "local" {
h := newHandler(handlerConfig{
unitTag: unitTag,
charmURL: charmURL,
validMetrics: validMetrics,
metricsFactory: metricFactory,
runner: runner,
})
listener, err = newSocketListener(socketName(paths.State.BaseDir, unitTag.String()), h)
if err != nil {
return nil, err
}
}
collector := &collect{
period: period,
agent: agent,
metricFactory: metricFactory,
charmdir: charmdir,
listener: listener,
runner: runner,
}
return collector, nil
}