implement ping
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m56s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m56s
This commit is contained in:
@@ -358,6 +358,19 @@ func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *RemoteHost) Ping() error {
|
||||
_, err := h.Call(Ping, Pong, nil)
|
||||
|
||||
if err != nil {
|
||||
h.MissedPings++
|
||||
log.Printf("Error pinging remote %s: %v\n, missed pings: %d", h.Host, err, h.MissedPings)
|
||||
|
||||
} else {
|
||||
h.MissedPings = 0
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *SyncedPool) AddRemote(host string) error {
|
||||
if host == "" || p.IsKnown(host) {
|
||||
return nil
|
||||
@@ -375,11 +388,28 @@ func (p *SyncedPool) AddRemote(host string) error {
|
||||
|
||||
//pool := NewRemoteGrainPool(host)
|
||||
remote := RemoteHost{
|
||||
Client: client,
|
||||
// Pool: pool,
|
||||
Host: host,
|
||||
Client: client,
|
||||
MissedPings: 0,
|
||||
Host: host,
|
||||
}
|
||||
go func() {
|
||||
for range time.Tick(time.Second * 2) {
|
||||
var err error
|
||||
|
||||
err = remote.Ping()
|
||||
if err != nil {
|
||||
for err != nil {
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
err = remote.Ping()
|
||||
if remote.MissedPings > 3 {
|
||||
log.Printf("Error pinging remote %s: %v\n, missed pings: %d", host, err, remote.MissedPings)
|
||||
p.RemoveHost(&remote)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
for range client.Errors {
|
||||
if client.ErrorCount > 3 {
|
||||
|
||||
Reference in New Issue
Block a user