move actor to pkg
This commit is contained in:
@@ -2,6 +2,7 @@ package proxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -37,24 +38,27 @@ func NewRemoteHost(host string) (*RemoteHost, error) {
|
||||
}
|
||||
|
||||
controlClient := messages.NewControlPlaneClient(conn)
|
||||
for retries := range 3 {
|
||||
ctx, pingCancel := context.WithTimeout(context.Background(), time.Second)
|
||||
_, pingErr := controlClient.Ping(ctx, &messages.Empty{})
|
||||
pingCancel()
|
||||
if pingErr == nil {
|
||||
break
|
||||
}
|
||||
if retries == 2 {
|
||||
log.Printf("AddRemote: ping %s failed after retries: %v", host, pingErr)
|
||||
conn.Close()
|
||||
return nil, pingErr
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
// go func() {
|
||||
// for retries := range 3 {
|
||||
// ctx, pingCancel := context.WithTimeout(context.Background(), time.Second)
|
||||
// _, pingErr := controlClient.Ping(ctx, &messages.Empty{})
|
||||
// pingCancel()
|
||||
// if pingErr == nil {
|
||||
// break
|
||||
// }
|
||||
// if retries == 2 {
|
||||
// log.Printf("AddRemote: ping %s failed after retries: %v", host, pingErr)
|
||||
// conn.Close()
|
||||
// p
|
||||
// }
|
||||
// time.Sleep(500 * time.Millisecond)
|
||||
// }
|
||||
// }()
|
||||
|
||||
transport := &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 100,
|
||||
DisableKeepAlives: false,
|
||||
IdleConnTimeout: 120 * time.Second,
|
||||
}
|
||||
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
|
||||
@@ -82,14 +86,19 @@ func (h *RemoteHost) Close() error {
|
||||
}
|
||||
|
||||
func (h *RemoteHost) Ping() bool {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
_, err := h.controlClient.Ping(ctx, &messages.Empty{})
|
||||
cancel()
|
||||
if err != nil {
|
||||
h.MissedPings++
|
||||
log.Printf("Ping %s failed (%d) %v", h.Host, h.MissedPings, err)
|
||||
return false
|
||||
var err error = errors.ErrUnsupported
|
||||
for err != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
_, err = h.controlClient.Ping(ctx, &messages.Empty{})
|
||||
cancel()
|
||||
if err != nil {
|
||||
h.MissedPings++
|
||||
log.Printf("Ping %s failed (%d) %v", h.Host, h.MissedPings, err)
|
||||
}
|
||||
if !h.IsHealthy() {
|
||||
return false
|
||||
}
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
}
|
||||
|
||||
h.MissedPings = 0
|
||||
|
||||
Reference in New Issue
Block a user