-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Use task broker's health endpoint #32
Merged
tomi
merged 5 commits into
main
from
cat-368-add-healthcheck-endpoint-for-task-broker-and-use-that
Nov 27, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2df86b
feat: Use task broker's health endpoint
tomi 8ae31d1
Update internal/http/check_until_broker_ready.go
tomi c6d0e22
Update internal/env/env.go
tomi 431a911
Update internal/ws/handshake.go
tomi ccf241c
chore: Fix comment and error message wording
tomi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"task-runner-launcher/internal/logs" | ||
"task-runner-launcher/internal/retry" | ||
"time" | ||
) | ||
|
||
func sendHealthRequest(taskBrokerURI string) (*http.Response, error) { | ||
url := fmt.Sprintf("%s/healthz", taskBrokerURI) | ||
|
||
client := &http.Client{ | ||
Timeout: 5 * time.Second, | ||
} | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return client.Do(req) | ||
} | ||
|
||
// CheckUntilBrokerReady checks forever until the task broker is ready, i.e. | ||
// In case of long-running migrations, readiness may take a long time. | ||
// Returns nil when ready. | ||
func CheckUntilBrokerReady(taskBrokerURI string) error { | ||
tomi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logs.Info("Waiting for task broker to be ready...") | ||
|
||
healthCheck := func() (string, error) { | ||
resp, err := sendHealthRequest(taskBrokerURI) | ||
tomi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return "", fmt.Errorf("task broker readiness check failed with error: %w", err) | ||
tomi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return "", fmt.Errorf("task broker readiness check failed with status code: %d", resp.StatusCode) | ||
} | ||
|
||
return "", nil | ||
} | ||
|
||
if _, err := retry.UnlimitedRetry("readiness-check", healthCheck); err != nil { | ||
return err | ||
} | ||
|
||
logs.Info("Task broker is ready") | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to repeat the server everywhere. Task broker is a server