本文整理汇总了Golang中github.com/juju/juju/worker.NewPeriodicWorker函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPeriodicWorker函数的具体用法?Golang NewPeriodicWorker怎么用?Golang NewPeriodicWorker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPeriodicWorker函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Manifold
// Manifold creates a metric sender manifold.
func Manifold(config ManifoldConfig) dependency.Manifold {
return dependency.Manifold{
Inputs: []string{
config.APICallerName,
config.MetricSpoolName,
},
Start: func(getResource dependency.GetResourceFunc) (worker.Worker, error) {
var apicaller base.APICaller
var factory spool.MetricFactory
err := getResource(config.APICallerName, &apicaller)
if err != nil {
return nil, errors.Trace(err)
}
err = getResource(config.MetricSpoolName, &factory)
if err != nil {
return nil, errors.Trace(err)
}
client := newMetricAdderClient(apicaller)
s := newSender(client, factory)
return worker.NewPeriodicWorker(s.Do, period, worker.NewTimer), nil
},
}
}
示例2: New
// New returns a worker.Worker for history Pruner.
func New(params *HistoryPrunerParams) worker.Worker {
w := &pruneWorker{
st: st,
params: params,
}
return worker.NewPeriodicWorker(w.doPruning, w.params.PruneInterval, worker.NewTimer)
}
示例3: NewWorker
// NewWorker returns a worker that lists published cloud
// images metadata, and records them in state.
func NewWorker(cl *imagemetadata.Client) worker.Worker {
// TODO (anastasiamac 2015-09-02) Bug#1491353 - don't ignore stop channel.
f := func(stop <-chan struct{}) error {
return cl.UpdateFromPublishedImages()
}
return worker.NewPeriodicWorker(f, updatePublicImageMetadataPeriod, worker.NewTimer)
}
示例4: NewWorker
// NewWorker returns a worker that lists block devices
// attached to the machine, and records them in state.
func NewWorker(l ListBlockDevicesFunc, b BlockDeviceSetter) worker.Worker {
var old []storage.BlockDevice
f := func(stop <-chan struct{}) error {
return doWork(l, b, &old)
}
return worker.NewPeriodicWorker(f, listBlockDevicesPeriod)
}
示例5: New
// New returns a worker.Worker for history Pruner.
func New(st *state.State, params *HistoryPrunerParams) worker.Worker {
w := &pruneWorker{
st: st,
params: params,
pruner: state.PruneStatusHistory,
}
return worker.NewPeriodicWorker(w.doPruning, w.params.PruneInterval, worker.NewTimer)
}
示例6: NewPruneWorker
func NewPruneWorker(st *state.State, params *HistoryPrunerParams, t worker.NewTimerFunc, psh pruneHistoryFunc) worker.Worker {
w := &pruneWorker{
st: st,
params: params,
pruner: psh,
}
return worker.NewPeriodicWorker(w.doPruning, w.params.PruneInterval, t)
}
示例7: NewPeriodicWorkerForTests
func NewPeriodicWorkerForTests(api Facade, params *VersionCheckerParams) worker.Worker {
w := &toolsVersionWorker{
api: api,
params: params,
}
periodicCall := func(stop <-chan struct{}) error {
return w.doCheck()
}
return worker.NewPeriodicWorker(periodicCall, params.CheckInterval, worker.NewTimer)
}
示例8: New
// New returns a worker.Worker for history Pruner.
func New(conf Config) (worker.Worker, error) {
if err := conf.Validate(); err != nil {
return nil, errors.Trace(err)
}
doPruning := func(stop <-chan struct{}) error {
err := conf.Facade.Prune(int(conf.MaxLogsPerEntity))
if err != nil {
return errors.Trace(err)
}
return nil
}
return worker.NewPeriodicWorker(doPruning, conf.PruneInterval, conf.NewTimer), nil
}
示例9: NewSender
// NewSender creates a new periodic worker that sends metrics
// to a collection service.
func NewSender(client metricsmanager.MetricsManagerClient) worker.Worker {
f := func(stopCh <-chan struct{}) error {
err := client.SendMetrics()
if err != nil {
senderLogger.Warningf("failed to send metrics %v - will retry later", err)
return nil
}
select {
case notify <- "senderCalled":
default:
}
return nil
}
return worker.NewPeriodicWorker(f, senderPeriod, worker.NewTimer)
}
示例10: newCleanup
// NewCleanup creates a new periodic worker that calls the CleanupOldMetrics api.
func newCleanup(client metricsmanager.MetricsManagerClient, notify chan string) worker.Worker {
f := func(stopCh <-chan struct{}) error {
err := client.CleanupOldMetrics()
if err != nil {
cleanupLogger.Warningf("failed to cleanup %v - will retry later", err)
return nil
}
select {
case notify <- "cleanupCalled":
default:
}
return nil
}
return worker.NewPeriodicWorker(f, cleanupPeriod, worker.NewTimer)
}
示例11: NewCleanup
// NewCleanup creates a new periodic worker that calls the CleanupOldMetrics api.
// If a notify channel is provided it will be signalled everytime the call is made.
func NewCleanup(client *metricsmanager.Client, notify chan struct{}) worker.Worker {
f := func(stopCh <-chan struct{}) error {
err := client.CleanupOldMetrics()
if err != nil {
logger.Warningf("failed to cleanup %v - will retry later", err)
return nil
}
select {
case notify <- struct{}{}:
default:
}
return nil
}
return worker.NewPeriodicWorker(f, time.Second)
}
示例12: NewPeriodicWorker
// NewPeriodicWorker returns a periodic worker, that will call a stop function
// when it is killed.
func NewPeriodicWorker(do worker.PeriodicWorkerCall, period time.Duration, newTimer func(time.Duration) worker.PeriodicTimer, stop func()) worker.Worker {
return &periodicWorker{
Worker: worker.NewPeriodicWorker(do, period, newTimer),
stop: stop,
}
}
示例13: doCheck
}
type Facade interface {
UpdateToolsVersion() error
}
// New returns a worker that periodically wakes up to try to find out and
// record the latest version of the tools so the update possibility can be
// displayed to the users on status.
var New = func(api Facade, params *VersionCheckerParams) worker.Worker {
w := &toolsVersionWorker{
api: api,
params: params,
}
f := func(stop <-chan struct{}) error {
return w.doCheck()
}
return worker.NewPeriodicWorker(f, params.CheckInterval, worker.NewTimer)
}
type toolsVersionWorker struct {
api Facade
params *VersionCheckerParams
}
func (w *toolsVersionWorker) doCheck() error {
err := w.api.UpdateToolsVersion()
return errors.Annotate(err, "cannot update tools information")
}
示例14: doWork
// ListBlockDevicesFunc is the type of a function that is supplied to
// NewWorker for listing block devices available on the local host.
type ListBlockDevicesFunc func() ([]storage.BlockDevice, error)
// DefaultListBlockDevices is the default function for listing block
// devices for the operating system of the local host.
var DefaultListBlockDevices ListBlockDevicesFunc
// NewWorker returns a worker that lists block devices
// attached to the machine, and records them in state.
var NewWorker = func(l ListBlockDevicesFunc, b BlockDeviceSetter) worker.Worker {
var old []storage.BlockDevice
f := func(stop <-chan struct{}) error {
return doWork(l, b, &old)
}
return worker.NewPeriodicWorker(f, listBlockDevicesPeriod, worker.NewTimer)
}
func doWork(listf ListBlockDevicesFunc, b BlockDeviceSetter, old *[]storage.BlockDevice) error {
blockDevices, err := listf()
if err != nil {
return err
}
storage.SortBlockDevices(blockDevices)
for _, blockDevice := range blockDevices {
sort.Strings(blockDevice.DeviceLinks)
}
if reflect.DeepEqual(blockDevices, *old) {
logger.Tracef("no changes to block devices detected")
return nil
}