MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / waitForServer

Function waitForServer

cli/cmd/login.go:73–95  ·  view source on GitHub ↗
(ctx context.Context, url string)

Source from the content-addressed store, hash-verified

71}
72
73func waitForServer(ctx context.Context, url string) error {
74 ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
75 defer cancel()
76
77 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
78 if err != nil {
79 return err
80 }
81
82 _, retryErr := backoff.Retry(ctx, func() (any, error) {
83 resp, err := http.DefaultClient.Do(req)
84 if err != nil {
85 return nil, err
86 }
87 defer resp.Body.Close()
88 _, _ = io.Copy(io.Discard, resp.Body)
89 if resp.StatusCode == http.StatusOK {
90 return nil, nil
91 }
92 return nil, fmt.Errorf("failed to connect to local server. error code: %d", resp.StatusCode)
93 }, backoff.WithBackOff(backoff.NewConstantBackOff(100*time.Millisecond)))
94 return retryErr
95}
96
97func runLogin(ctx context.Context, cmd *cobra.Command) (err error) {
98 accountsURL := env.GetEnvOrDefault("CLOUDQUERY_ACCOUNTS_URL", defaultAccountsURL)

Callers 1

runLoginFunction · 0.85

Calls 2

ErrorfMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected