當前位置: 首頁>>代碼示例>>Golang>>正文


Golang worker.NewPeriodicWorker函數代碼示例

本文整理匯總了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
		},
	}
}
開發者ID:imoapps,項目名稱:juju,代碼行數:26,代碼來源:manifold.go

示例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)
}
開發者ID:guycook,項目名稱:tenets,代碼行數:8,代碼來源:worker4.go

示例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)
}
開發者ID:howbazaar,項目名稱:juju,代碼行數:9,代碼來源:metadataupdater.go

示例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)
}
開發者ID:Pankov404,項目名稱:juju,代碼行數:9,代碼來源:diskmanager.go

示例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)
}
開發者ID:guycook,項目名稱:tenets,代碼行數:9,代碼來源:worker.go

示例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)
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:8,代碼來源:export_test.go

示例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)
}
開發者ID:howbazaar,項目名稱:juju,代碼行數:10,代碼來源:export_test.go

示例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
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:15,代碼來源:worker.go

示例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)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:17,代碼來源:sender.go

示例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)
}
開發者ID:bac,項目名稱:juju,代碼行數:16,代碼來源:cleanup.go

示例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)
}
開發者ID:zhouqt,項目名稱:juju,代碼行數:17,代碼來源:cleanup.go

示例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,
	}
}
開發者ID:exekias,項目名稱:juju,代碼行數:8,代碼來源:listener.go

示例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")
}
開發者ID:AlexisBruemmer,項目名稱:juju,代碼行數:30,代碼來源:worker.go

示例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
	}
開發者ID:bac,項目名稱:juju,代碼行數:31,代碼來源:diskmanager.go


注:本文中的github.com/juju/juju/worker.NewPeriodicWorker函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。