github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/toolsversionchecker/worker.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package toolsversionchecker 5 6 import ( 7 "time" 8 9 "github.com/juju/errors" 10 11 "github.com/juju/juju/worker" 12 ) 13 14 // VersionCheckerParams holds params for the version checker worker.. 15 type VersionCheckerParams struct { 16 CheckInterval time.Duration 17 } 18 19 type Facade interface { 20 UpdateToolsVersion() error 21 } 22 23 // New returns a worker that periodically wakes up to try to find out and 24 // record the latest version of the tools so the update possibility can be 25 // displayed to the users on status. 26 var New = func(api Facade, params *VersionCheckerParams) worker.Worker { 27 w := &toolsVersionWorker{ 28 api: api, 29 params: params, 30 } 31 32 f := func(stop <-chan struct{}) error { 33 return w.doCheck() 34 } 35 return worker.NewPeriodicWorker(f, params.CheckInterval, worker.NewTimer) 36 } 37 38 type toolsVersionWorker struct { 39 api Facade 40 params *VersionCheckerParams 41 } 42 43 func (w *toolsVersionWorker) doCheck() error { 44 err := w.api.UpdateToolsVersion() 45 return errors.Annotate(err, "cannot update tools information") 46 }