fix: lazy check

This commit is contained in:
wwqgtxx
2022-10-30 23:08:18 +08:00
parent dedb9122df
commit b9d8b69889
10 changed files with 36 additions and 22 deletions

View File

@ -35,16 +35,13 @@ func (hc *HealthCheck) process() {
go func() {
time.Sleep(30 * time.Second)
hc.check()
hc.lazyCheck()
}()
for {
select {
case <-ticker.C:
now := time.Now().Unix()
if !hc.lazy || now-hc.lastTouch.Load() < int64(hc.interval) {
hc.check()
}
hc.lazyCheck()
case <-hc.done:
ticker.Stop()
return
@ -52,6 +49,16 @@ func (hc *HealthCheck) process() {
}
}
func (hc *HealthCheck) lazyCheck() bool {
now := time.Now().Unix()
if !hc.lazy || now-hc.lastTouch.Load() < int64(hc.interval) {
hc.check()
return true
} else {
return false
}
}
func (hc *HealthCheck) setProxy(proxies []C.Proxy) {
hc.proxies = proxies
}