chore(repo): reinitialize repository
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package workspaceruntime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type endpointProbe struct {
|
||||
attempts int
|
||||
dialTimeout time.Duration
|
||||
retryDelay time.Duration
|
||||
}
|
||||
|
||||
func newEndpointProbe() *endpointProbe {
|
||||
return &endpointProbe{
|
||||
attempts: 20,
|
||||
dialTimeout: 500 * time.Millisecond,
|
||||
retryDelay: 250 * time.Millisecond,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *endpointProbe) wait(endpoint string) error {
|
||||
address := strings.TrimPrefix(endpoint, "http://")
|
||||
var lastErr error
|
||||
for attempt := 0; attempt < p.attempts; attempt++ {
|
||||
conn, err := net.DialTimeout("tcp", address, p.dialTimeout)
|
||||
if err == nil {
|
||||
_ = conn.Close()
|
||||
return nil
|
||||
}
|
||||
lastErr = err
|
||||
time.Sleep(p.retryDelay)
|
||||
}
|
||||
return fmt.Errorf("runner endpoint %s is not reachable: %w", endpoint, lastErr)
|
||||
}
|
||||
Reference in New Issue
Block a user