gh-ost/vendor/github.com/ngaut/systimemon/systime_mon.go
2017-02-12 13:17:56 +02:00

25 lines
489 B
Go

package systimemon
import (
"time"
"github.com/ngaut/log"
)
// StartMonitor will call systimeErrHandler if system time jump backward.
func StartMonitor(now func() time.Time, systimeErrHandler func()) {
log.Info("start system time monitor")
tick := time.NewTicker(100 * time.Millisecond)
defer tick.Stop()
for {
last := now()
select {
case <-tick.C:
if now().Sub(last) < 0 {
log.Errorf("system time jump backward, last:%v", last)
systimeErrHandler()
}
}
}
}