本文整理汇总了Golang中github.com/juju/juju/worker.NewRunner函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRunner函数的具体用法?Golang NewRunner怎么用?Golang NewRunner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRunner函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newMetricsManager
// NewMetricsManager creates a runner that will run the metricsmanagement workers.
func newMetricsManager(client metricsmanager.MetricsManagerClient, notify chan string) (worker.Runner, error) {
// TODO(fwereade): break this out into separate manifolds (with their own facades).
// Periodic workers automatically retry so none should return an error. If they do
// it's ok to restart them individually.
isFatal := func(error) bool {
return false
}
// All errors are equal
moreImportant := func(error, error) bool {
return false
}
runner := worker.NewRunner(isFatal, moreImportant, worker.RestartDelay)
err := runner.StartWorker("sender", func() (worker.Worker, error) {
return newSender(client, notify), nil
})
if err != nil {
return nil, errors.Trace(err)
}
err = runner.StartWorker("cleanup", func() (worker.Worker, error) {
return newCleanup(client, notify), nil
})
if err != nil {
return nil, errors.Trace(err)
}
return runner, nil
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:metricmanager.go
示例2: Init
// Init initializes the command for running.
func (a *UnitAgent) Init(args []string) error {
if a.UnitName == "" {
return cmdutil.RequiredError("unit-name")
}
if !names.IsValidUnit(a.UnitName) {
return fmt.Errorf(`--unit-name option expects "<service>/<n>" argument`)
}
if err := a.AgentConf.CheckArgs(args); err != nil {
return err
}
a.runner = worker.NewRunner(cmdutil.IsFatal, cmdutil.MoreImportant, worker.RestartDelay)
if !a.logToStdErr {
if err := a.ReadConfig(a.Tag().String()); err != nil {
return err
}
agentConfig := a.CurrentConfig()
// the writer in ctx.stderr gets set as the loggo writer in github.com/juju/cmd/logging.go
a.ctx.Stderr = &lumberjack.Logger{
Filename: agent.LogFilename(agentConfig),
MaxSize: 300, // megabytes
MaxBackups: 2,
}
}
return nil
}
开发者ID:makyo,项目名称:juju,代码行数:30,代码来源:unit.go
示例3: TestOneWorkerStartWhenStopping
func (*RunnerSuite) TestOneWorkerStartWhenStopping(c *gc.C) {
runner := worker.NewRunner(allFatal, noImportance, 3*time.Second)
starter := newTestWorkerStarter()
starter.stopWait = make(chan struct{})
// Start a worker, and wait for it.
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
// XXX the above does not imply the *runner* knows it's started.
// voodoo sleep ahoy!
time.Sleep(testing.ShortWait)
// Stop the worker, which will block...
err = runner.StopWorker("id")
c.Assert(err, jc.ErrorIsNil)
// While it's still blocked, try to start another.
err = runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
// Unblock the stopping worker, and check that the task is
// restarted immediately without the usual restart timeout
// delay.
t0 := time.Now()
close(starter.stopWait)
starter.assertStarted(c, false) // stop notification
starter.assertStarted(c, true) // start notification
restartDuration := time.Since(t0)
if restartDuration > 1*time.Second {
c.Fatalf("task did not restart immediately")
}
c.Assert(worker.Stop(runner), gc.IsNil)
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:runner_test.go
示例4: NewMetricsManager
// NewMetricsManager creates a runner that will run the metricsmanagement workers.
func NewMetricsManager(client metricsmanager.MetricsManagerClient) (worker.Runner, error) {
// Periodic workers automatically retry so none should return an error. If they do
// it's ok to restart them individually.
isFatal := func(error) bool {
return false
}
// All errors are equal
moreImportant := func(error, error) bool {
return false
}
runner := worker.NewRunner(isFatal, moreImportant, worker.RestartDelay)
err := runner.StartWorker("sender", func() (worker.Worker, error) {
return NewSender(client), nil
})
if err != nil {
return nil, errors.Trace(err)
}
err = runner.StartWorker("cleanup", func() (worker.Worker, error) {
return NewCleanup(client), nil
})
if err != nil {
return nil, errors.Trace(err)
}
return runner, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:27,代码来源:metricmanager.go
示例5: mongoWorker
func (a *agent) mongoWorker() (worker.Worker, error) {
dialInfo := gitjujutesting.MgoDialInfo(coretesting.Certs, a.hostPort)
session, err := mgo.DialWithInfo(dialInfo)
if err != nil {
return nil, err
}
mc := &mongoConn{
localHostPort: a.hostPort,
session: session,
}
fn := func(err0, err1 error) bool { return true }
runner := worker.NewRunner(connectionIsFatal(mc), fn, worker.RestartDelay)
singularRunner, err := singular.New(runner, mc)
if err != nil {
return nil, fmt.Errorf("cannot start singular runner: %v", err)
}
a.notify.workerConnected()
singularRunner.StartWorker(fmt.Sprint("worker-", a.notify.id), func() (worker.Worker, error) {
return worker.NewSimpleWorker(func(stop <-chan struct{}) error {
return a.worker(session, stop)
}), nil
})
return runner, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:25,代码来源:mongo_test.go
示例6: loop
func (m *modelWorkerManager) loop() error {
m.runner = worker.NewRunner(
neverFatal, neverImportant, m.config.ErrorDelay,
)
if err := m.catacomb.Add(m.runner); err != nil {
return errors.Trace(err)
}
watcher := m.config.Backend.WatchModels()
if err := m.catacomb.Add(watcher); err != nil {
return errors.Trace(err)
}
for {
select {
case <-m.catacomb.Dying():
return m.catacomb.ErrDying()
case uuids, ok := <-watcher.Changes():
if !ok {
return errors.New("changes stopped")
}
for _, modelUUID := range uuids {
if err := m.ensure(m.config.ControllerUUID, modelUUID); err != nil {
return errors.Trace(err)
}
}
}
}
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:modelworkermanager.go
示例7: setupContainerWorker
func (s *ContainerSetupSuite) setupContainerWorker(c *gc.C, tag names.MachineTag) (worker.StringsWatchHandler, worker.Runner) {
testing.PatchExecutable(c, s, "ubuntu-cloudimg-query", containertesting.FakeLxcURLScript)
runner := worker.NewRunner(allFatal, noImportance)
pr := s.st.Provisioner()
machine, err := pr.Machine(tag)
c.Assert(err, jc.ErrorIsNil)
err = machine.SetSupportedContainers(instance.ContainerTypes...)
c.Assert(err, jc.ErrorIsNil)
cfg := s.AgentConfigForTag(c, tag)
watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
params := provisioner.ContainerSetupParams{
Runner: runner,
WorkerName: watcherName,
SupportedContainers: instance.ContainerTypes,
ImageURLGetter: &containertesting.MockURLGetter{},
Machine: machine,
Provisioner: pr,
Config: cfg,
InitLock: s.initLock,
}
handler := provisioner.NewContainerSetupHandler(params)
runner.StartWorker(watcherName, func() (worker.Worker, error) {
return worker.NewStringsWorker(handler), nil
})
return handler, runner
}
开发者ID:chrisjohnston,项目名称:juju,代码行数:27,代码来源:container_initialisation_test.go
示例8: TestOneWorkerStartWhenStopping
func (*runnerSuite) TestOneWorkerStartWhenStopping(c *gc.C) {
worker.RestartDelay = 3 * time.Second
runner := worker.NewRunner(allFatal, noImportance)
starter := newTestWorkerStarter()
starter.stopWait = make(chan struct{})
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
err = runner.StopWorker("id")
c.Assert(err, jc.ErrorIsNil)
err = runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
close(starter.stopWait)
starter.assertStarted(c, false)
// Check that the task is restarted immediately without
// the usual restart timeout delay.
t0 := time.Now()
starter.assertStarted(c, true)
restartDuration := time.Since(t0)
if restartDuration > 1*time.Second {
c.Fatalf("task did not restart immediately")
}
c.Assert(worker.Stop(runner), gc.IsNil)
}
开发者ID:Pankov404,项目名称:juju,代码行数:26,代码来源:runner_test.go
示例9: newRunner
func newRunner() worker.Runner {
return worker.NewRunner(
func(err error) bool {
return err == errFatal
},
func(err0, err1 error) bool { return true },
)
}
开发者ID:kapilt,项目名称:juju,代码行数:8,代码来源:singular_test.go
示例10: TestOneWorkerStartFatalError
func (*runnerSuite) TestOneWorkerStartFatalError(c *gc.C) {
runner := worker.NewRunner(allFatal, noImportance)
starter := newTestWorkerStarter()
starter.startErr = errors.New("cannot start test task")
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
err = runner.Wait()
c.Assert(err, gc.Equals, starter.startErr)
}
开发者ID:Pankov404,项目名称:juju,代码行数:9,代码来源:runner_test.go
示例11: TestOneWorkerStart
func (*runnerSuite) TestOneWorkerStart(c *gc.C) {
runner := worker.NewRunner(noneFatal, noImportance)
starter := newTestWorkerStarter()
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
c.Assert(worker.Stop(runner), gc.IsNil)
starter.assertStarted(c, false)
}
开发者ID:Pankov404,项目名称:juju,代码行数:10,代码来源:runner_test.go
示例12: TestOneWorkerStartStop
func (*runnerSuite) TestOneWorkerStartStop(c *gc.C) {
runner := worker.NewRunner(allFatal, noImportance, time.Millisecond)
starter := newTestWorkerStarter()
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
err = runner.StopWorker("id")
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, false)
c.Assert(worker.Stop(runner), gc.IsNil)
}
开发者ID:felicianotech,项目名称:juju,代码行数:11,代码来源:runner_test.go
示例13: TestOneWorkerStopFatalError
func (*runnerSuite) TestOneWorkerStopFatalError(c *gc.C) {
runner := worker.NewRunner(allFatal, noImportance)
starter := newTestWorkerStarter()
starter.stopErr = errors.New("stop error")
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
err = runner.StopWorker("id")
c.Assert(err, jc.ErrorIsNil)
err = runner.Wait()
c.Assert(err, gc.Equals, starter.stopErr)
}
开发者ID:Pankov404,项目名称:juju,代码行数:12,代码来源:runner_test.go
示例14: TestOneWorkerDieFatalError
func (*runnerSuite) TestOneWorkerDieFatalError(c *gc.C) {
runner := worker.NewRunner(allFatal, noImportance)
starter := newTestWorkerStarter()
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
dieErr := errors.New("error when running")
starter.die <- dieErr
err = runner.Wait()
c.Assert(err, gc.Equals, dieErr)
starter.assertStarted(c, false)
}
开发者ID:Pankov404,项目名称:juju,代码行数:12,代码来源:runner_test.go
示例15: TestOneWorkerFinish
func (*runnerSuite) TestOneWorkerFinish(c *gc.C) {
runner := worker.NewRunner(noneFatal, noImportance, time.Millisecond)
starter := newTestWorkerStarter()
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
starter.die <- nil
starter.assertStarted(c, false)
starter.assertNeverStarted(c)
c.Assert(worker.Stop(runner), gc.IsNil)
}
开发者ID:felicianotech,项目名称:juju,代码行数:13,代码来源:runner_test.go
示例16: NewEnvWorkerManager
// NewEnvWorkerManager returns a Worker which manages a worker which
// needs to run on a per environment basis. It takes a function which will
// be called to start a worker for a new environment. This worker
// will be killed when an environment goes away.
func NewEnvWorkerManager(
st InitialState,
startEnvWorker func(InitialState, *state.State) (worker.Worker, error),
) worker.Worker {
m := &envWorkerManager{
st: st,
startEnvWorker: startEnvWorker,
}
m.runner = worker.NewRunner(cmdutil.IsFatal, cmdutil.MoreImportant)
go func() {
defer m.tomb.Done()
m.tomb.Kill(m.loop())
}()
return m
}
开发者ID:Pankov404,项目名称:juju,代码行数:19,代码来源:envworkermanager.go
示例17: TestOneWorkerRestartDelay
func (*runnerSuite) TestOneWorkerRestartDelay(c *gc.C) {
worker.RestartDelay = 100 * time.Millisecond
runner := worker.NewRunner(noneFatal, noImportance)
starter := newTestWorkerStarter()
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, gc.IsNil)
starter.assertStarted(c, true)
starter.die <- fmt.Errorf("non-fatal error")
starter.assertStarted(c, false)
t0 := time.Now()
starter.assertStarted(c, true)
restartDuration := time.Since(t0)
if restartDuration < worker.RestartDelay {
c.Fatalf("restart delay was not respected; got %v want %v", restartDuration, worker.RestartDelay)
}
}
开发者ID:rogpeppe,项目名称:juju,代码行数:16,代码来源:runner_test.go
示例18: setupContainerWorker
func (s *ContainerSetupSuite) setupContainerWorker(c *gc.C, tag names.MachineTag) (worker.StringsWatchHandler, worker.Runner) {
runner := worker.NewRunner(allFatal, noImportance)
pr := s.st.Provisioner()
machine, err := pr.Machine(tag)
c.Assert(err, gc.IsNil)
err = machine.SetSupportedContainers(instance.ContainerTypes...)
c.Assert(err, gc.IsNil)
cfg := s.AgentConfigForTag(c, tag)
watcherName := fmt.Sprintf("%s-container-watcher", machine.Id())
handler := provisioner.NewContainerSetupHandler(runner, watcherName, instance.ContainerTypes, machine, pr, cfg, s.initLock)
runner.StartWorker(watcherName, func() (worker.Worker, error) {
return worker.NewStringsWorker(handler), nil
})
return handler, runner
}
开发者ID:zhouqt,项目名称:juju,代码行数:16,代码来源:container_initialisation_test.go
示例19: TestErrorImportance
func (*runnerSuite) TestErrorImportance(c *gc.C) {
moreImportant := func(err0, err1 error) bool {
return err0.(errorLevel) > err1.(errorLevel)
}
id := func(i int) string { return fmt.Sprint(i) }
runner := worker.NewRunner(allFatal, moreImportant)
for i := 0; i < 10; i++ {
starter := newTestWorkerStarter()
starter.stopErr = errorLevel(i)
err := runner.StartWorker(id(i), testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
}
err := runner.StopWorker(id(4))
c.Assert(err, jc.ErrorIsNil)
err = runner.Wait()
c.Assert(err, gc.Equals, errorLevel(9))
}
开发者ID:Pankov404,项目名称:juju,代码行数:17,代码来源:runner_test.go
示例20: TestOneWorkerRestart
func (*runnerSuite) TestOneWorkerRestart(c *gc.C) {
runner := worker.NewRunner(noneFatal, noImportance)
starter := newTestWorkerStarter()
err := runner.StartWorker("id", testWorkerStart(starter))
c.Assert(err, jc.ErrorIsNil)
starter.assertStarted(c, true)
// Check it restarts a few times time.
for i := 0; i < 3; i++ {
starter.die <- fmt.Errorf("an error")
starter.assertStarted(c, false)
starter.assertStarted(c, true)
}
c.Assert(worker.Stop(runner), gc.IsNil)
starter.assertStarted(c, false)
}
开发者ID:Pankov404,项目名称:juju,代码行数:17,代码来源:runner_test.go
注:本文中的github.com/juju/juju/worker.NewRunner函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论