github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/metricworker/cleanup.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 "time" 8 9 "github.com/juju/loggo" 10 11 "github.com/juju/juju/api/metricsmanager" 12 "github.com/juju/juju/worker" 13 ) 14 15 var cleanupLogger = loggo.GetLogger("juju.worker.metricworker.cleanup") 16 17 const cleanupPeriod = time.Hour 18 19 // NewCleanup creates a new periodic worker that calls the CleanupOldMetrics api. 20 func newCleanup(client metricsmanager.MetricsManagerClient, notify chan string) worker.Worker { 21 f := func(stopCh <-chan struct{}) error { 22 err := client.CleanupOldMetrics() 23 if err != nil { 24 cleanupLogger.Warningf("failed to cleanup %v - will retry later", err) 25 return nil 26 } 27 select { 28 case notify <- "cleanupCalled": 29 default: 30 } 31 return nil 32 } 33 return worker.NewPeriodicWorker(f, cleanupPeriod, worker.NewTimer) 34 }