예제 #1
0
파일: sender.go 프로젝트: imoapps/juju
// 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)
}
예제 #2
0
파일: cleanup.go 프로젝트: bac/juju
// 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)
}