github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/metricworker/metricmanager.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package metricworker 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/api/metricsmanager" 10 "github.com/juju/juju/worker" 11 ) 12 13 // NewMetricsManager creates a runner that will run the metricsmanagement workers. 14 func newMetricsManager(client metricsmanager.MetricsManagerClient, notify chan string) (worker.Runner, error) { 15 // TODO(fwereade): break this out into separate manifolds (with their own facades). 16 17 // Periodic workers automatically retry so none should return an error. If they do 18 // it's ok to restart them individually. 19 isFatal := func(error) bool { 20 return false 21 } 22 // All errors are equal 23 moreImportant := func(error, error) bool { 24 return false 25 } 26 27 runner := worker.NewRunner(isFatal, moreImportant, worker.RestartDelay) 28 err := runner.StartWorker("sender", func() (worker.Worker, error) { 29 return newSender(client, notify), nil 30 }) 31 32 if err != nil { 33 return nil, errors.Trace(err) 34 } 35 36 err = runner.StartWorker("cleanup", func() (worker.Worker, error) { 37 return newCleanup(client, notify), nil 38 }) 39 if err != nil { 40 return nil, errors.Trace(err) 41 } 42 return runner, nil 43 }