Exemplo n.º 1
0
// 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)
}
Exemplo n.º 2
0
Arquivo: cleanup.go Projeto: 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)
}