-
-
Notifications
You must be signed in to change notification settings - Fork 379
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 4 commits
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 | ||||||
|
|
@@ -91,6 +92,33 @@ def get_container(version=None, quit_if_not_exists=True) -> Optional[Container]: | |||||
| return None | ||||||
|
|
||||||
|
|
||||||
| def _is_backend_ready(endpoint) -> bool: | ||||||
| try: | ||||||
| response = requests.get(endpoint) | ||||||
| response.raise_for_status() | ||||||
| return "UP" == response.json()["status"] | ||||||
| except KeyboardInterrupt: | ||||||
| raise click.Abort() | ||||||
| except BaseException: | ||||||
kevinmessiaen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| return False | ||||||
|
|
||||||
|
|
||||||
| def _wait_backend_ready(port: int) -> bool: | ||||||
| endpoint = f"http://localhost:{port}/management/health" | ||||||
| backoff_time = 2 | ||||||
| max_duration_second = 3 * 60 | ||||||
| started_time = time.time() | ||||||
| up = False | ||||||
|
|
||||||
| while not up or time.time() - started_time > max_duration_second: | ||||||
kevinmessiaen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| time.sleep(backoff_time) | ||||||
| up = _is_backend_ready(endpoint) | ||||||
| click.echo(".", nl=False) | ||||||
|
|
||||||
| click.echo(".") | ||||||
| return up | ||||||
|
|
||||||
|
|
||||||
| def _start(attached=False, version=None): | ||||||
| logger.info("Starting Giskard Server") | ||||||
|
|
||||||
|
|
@@ -115,7 +143,16 @@ def _start(attached=False, version=None): | |||||
| volumes={home_volume.name: {"bind": "/home/giskard/datadir", "mode": "rw"}}, | ||||||
| ) | ||||||
| container.start() | ||||||
| logger.info(f"Giskard Server {version} started. You can access it at http://localhost:{port}") | ||||||
|
|
||||||
| up = _wait_backend_ready(port) | ||||||
|
|
||||||
| if up: | ||||||
| logger.info(f"Giskard Server {version} started. You can access it at http://localhost:{port}") | ||||||
| else: | ||||||
| logger.warning( | ||||||
| "Giskard backend takes unusually long time to start, please check the logs with `giskard server " | ||||||
| "logs backend" | ||||||
|
||||||
| "logs backend" | |
| "logs backend`" |
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.
or perhaps to make it even more readable you can break the long line before the giskard server logs backend command, for example after the first comma
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 👍