try ping again after no response immediately
This commit is contained in:
6
main.go
6
main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/go-ping/ping"
|
||||
@@ -38,6 +39,7 @@ var (
|
||||
journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout")
|
||||
configFlag = flag.String("config", "config.yaml", "Set config file to use")
|
||||
reBandwidth = regexp.MustCompile(`(?m)bandwidth\s(\d+)Mbit`)
|
||||
NoResponseError = errors.New("no response")
|
||||
)
|
||||
|
||||
type UploadManager struct {
|
||||
@@ -115,7 +117,7 @@ func doPing(host string, count int, interval time.Duration) (*ping.Statistics, e
|
||||
}
|
||||
log.Debugf("[PING] %s: %s±%s %d%% loss", host, pinger.Statistics().AvgRtt, pinger.Statistics().StdDevRtt, pinger.Statistics().PacketLoss)
|
||||
if pinger.Statistics().PacketLoss == 100 {
|
||||
return nil, fmt.Errorf("no response")
|
||||
return nil, NoResponseError
|
||||
}
|
||||
return pinger.Statistics(), nil
|
||||
}
|
||||
@@ -190,7 +192,9 @@ outerLoop:
|
||||
stats, err = doPing(conf.Host, conf.ConformationPPP, time.Second)
|
||||
if err != nil {
|
||||
log.Warningf("ping to %s failed: %v", conf.Host, err)
|
||||
if !errors.Is(err, NoResponseError) {
|
||||
time.Sleep(time.Duration(conf.Interval) * time.Minute)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user