Move ticker to new module
This commit is contained in:
30
src/background/ticker.go
Normal file
30
src/background/ticker.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package background
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.fjla.uk/owlboard/timetable-mgr/cif"
|
||||
"git.fjla.uk/owlboard/timetable-mgr/helpers"
|
||||
"git.fjla.uk/owlboard/timetable-mgr/log"
|
||||
)
|
||||
|
||||
const frequency = 5 * time.Millisecond // Figure out a sensible frequency!
|
||||
|
||||
func InitTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
||||
go runTicker(cfg, stop)
|
||||
}
|
||||
|
||||
func runTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
||||
log.Msg.Sugar().Infof("Starting background ticker, runs every %s", frequency)
|
||||
ticker := time.NewTicker(frequency)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
case <-ticker.C:
|
||||
cif.CifCheck(cfg)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user