move actor to pkg
Some checks failed
Build and Publish / Metadata (push) Has been cancelled
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled
Build and Publish / BuildAndDeployArm64 (push) Has been cancelled

This commit is contained in:
matst80
2025-10-13 10:29:55 +02:00
parent c6671ceef0
commit 1575b3a829
29 changed files with 584 additions and 654 deletions

View File

@@ -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