refactor(client): simplify HTTP client and reporter daemon implementation
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:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user