2
0

refactor(client): simplify HTTP client and reporter daemon implementation
Some checks failed
CI / build-and-test (push) Has been cancelled
Release / build (amd64, darwin) (push) Successful in 57s
Release / build (amd64, linux) (push) Successful in 1m4s
Release / build (amd64, windows) (push) Successful in 1m13s
Release / build (arm64, linux) (push) Successful in 53s
Release / build (arm64, darwin) (push) Successful in 1m16s
Release / release (push) Successful in 24s

Use http.DefaultClient when TLS verification is not skipped, removing unnecessary custom transport configuration. Replace select-based daemon loop with time.AfterFunc for cleaner implementation and remove verbose error logging in RunDaemon.
This commit is contained in:
2026-01-25 14:31:47 -05:00
parent 899ca015b1
commit f33d0a54c4
2 changed files with 10 additions and 29 deletions

View File

@@ -8,7 +8,6 @@ import (
"crypto/tls"
"net/http"
"strings"
"time"
"code.gitea.io/actions-proto-go/ping/v1/pingv1connect"
"code.gitea.io/actions-proto-go/runner/v1/runnerv1connect"
@@ -16,24 +15,16 @@ import (
)
func getHTTPClient(endpoint string, insecure bool) *http.Client {
transport := &http.Transport{
MaxIdleConns: 10,
MaxIdleConnsPerHost: 5,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
DisableKeepAlives: false,
}
if strings.HasPrefix(endpoint, "https://") && insecure {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
}
return &http.Client{
Transport: transport,
Timeout: 30 * time.Second,
}
return http.DefaultClient
}
// New returns a new runner client.

View File

@@ -190,20 +190,10 @@ func (r *Reporter) RunDaemon() {
return
}
if err := r.ReportLog(false); err != nil {
log.WithError(err).Warn("failed to report log")
}
if err := r.ReportState(); err != nil {
log.WithError(err).Warn("failed to report state")
}
_ = r.ReportLog(false)
_ = r.ReportState()
// Use select with context to allow clean shutdown
select {
case <-r.ctx.Done():
return
case <-time.After(time.Second):
r.RunDaemon()
}
time.AfterFunc(time.Second, r.RunDaemon)
}
// Logf adds a formatted log message to the report.