-
-
Notifications
You must be signed in to change notification settings - Fork 508
Await for backend to be ready before showing link #1172
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
Changes from 1 commit
1e8d035
7f4365b
c1398ce
c7d0e2c
86dfbef
0d8d8dd
d089dae
4a772b5
ea93749
74a3e13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||
| import logging | ||||||
| import os | ||||||
| import time | ||||||
| from pathlib import Path | ||||||
| from typing import Optional | ||||||
| from urllib.parse import urlparse | ||||||
|
|
@@ -25,7 +26,6 @@ | |||||
| giskard_settings_path = settings.home_dir / "server-settings.yml" | ||||||
| IMAGE_NAME = "docker.io/giskardai/giskard" | ||||||
|
|
||||||
|
|
||||||
| def create_docker_client() -> DockerClient: | ||||||
| try: | ||||||
| return docker.from_env() | ||||||
|
|
@@ -96,6 +96,30 @@ def get_container(version=None, quit_if_not_exists=True) -> Optional[Container]: | |||||
| return None | ||||||
|
|
||||||
|
|
||||||
| def _backend_ready(endpoint) -> bool: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| try: | ||||||
| response = requests.get(endpoint) | ||||||
|
|
||||||
| if response.status_code != 200: | ||||||
| return False | ||||||
|
|
||||||
| return "UP" == response.json()['components']['readinessState']['status'] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| except OSError: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this case you can even replace with since it'll be caught by the same BaseException handler |
||||||
| return False | ||||||
| except KeyError: | ||||||
| return False | ||||||
|
|
||||||
|
|
||||||
| def _await_backend_ready(port: int): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: await has an asynchronous connotation in python (async/await). There's also an async sleep counterpart that'd be used for it:
Suggested change
|
||||||
| endpoint = f"http://localhost:{port}/management/health" | ||||||
| backoff_time = 2 | ||||||
| up = False | ||||||
|
|
||||||
| while not up: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have a waiting limit. Let's say we wait for 3 minutes and if Also I think it's worth adding a feedback while waiting, for example printing dots every should do the trick, because print(end='') won't work in the loop without explicit stdout flushing |
||||||
| time.sleep(backoff_time) | ||||||
| up = _backend_ready(endpoint) | ||||||
|
|
||||||
|
|
||||||
| def _start(attached=False, version=None): | ||||||
| logger.info("Starting Giskard Server") | ||||||
|
|
||||||
|
|
@@ -120,6 +144,9 @@ def _start(attached=False, version=None): | |||||
| volumes={home_volume.name: {"bind": "/home/giskard/datadir", "mode": "rw"}}, | ||||||
| ) | ||||||
| container.start() | ||||||
|
|
||||||
| _await_backend_ready(port) | ||||||
|
|
||||||
| logger.info(f"Giskard Server {version} started. You can access it at http://localhost:{port}") | ||||||
|
|
||||||
|
|
||||||
|
|
||||||


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.
good job using the existing API 👍