generated from kedaya_haitao/template
29 lines
720 B
Go
29 lines
720 B
Go
package proxy
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitea.timerzz.com/timerzz/proxy-detector/log"
|
|
healthcheck "gitea.timerzz.com/timerzz/proxy-detector/pkg/health-check"
|
|
"gitea.timerzz.com/timerzz/proxy-detector/pkg/proxy/structs"
|
|
)
|
|
|
|
func CronHealthCheck(ctx context.Context, interval int) {
|
|
ticker := time.NewTicker(time.Duration(interval) * time.Minute)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
log.Infoln("Starting health check...")
|
|
proxies := healthcheck.CleanBadProxies(ctx, structs.ProxiesList.Get())
|
|
structs.ProxiesList.Replace(proxies)
|
|
log.Infoln("Health check completed.")
|
|
log.Infoln(fmt.Sprintf("目前共%d个代理", len(proxies)))
|
|
}
|
|
}
|
|
}
|