timetable-mgr/background/ticker.go
Fred Boniface 493fb41da8
Some checks failed
Go Test / test (push) Failing after 48s
Reorganise repo
2024-04-05 22:23:42 +01:00

35 lines
875 B
Go

package background
import (
"time"
"git.fjla.uk/owlboard/timetable-mgr/cif"
"git.fjla.uk/owlboard/timetable-mgr/corpus"
"git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log"
)
const frequency = 600 * time.Hour // Figure out a sensible frequency!
// Starts a background ticker to run background tasks. Uses the frequency configured in the background/ticker.go file
func InitTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
go runTicker(cfg, stop)
}
// Runs the ticker and handles tick events
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:
go cif.CheckCif(cfg)
go corpus.CheckCorpus(cfg)
}
}
}