potiuk commented on code in PR #46786:
URL: https://github.com/apache/airflow/pull/46786#discussion_r1957102583
##########
dev/breeze/src/airflow_breeze/utils/docker_command_utils.py:
##########
@@ -843,9 +843,53 @@ def enter_shell(shell_params: ShellParams, output: Output
| None = None) -> RunC
get_console().print(f"[red]Error {command_result.returncode}
returned[/]")
if get_verbose():
get_console().print(command_result.stderr)
+ notify_on_unhealthy_backend_container(shell_params.project_name,
shell_params.backend, output)
return command_result
+def notify_on_unhealthy_backend_container(project_name: str, backend: str,
output: Output | None = None):
+ """Put emphasis on unhealthy backend container and `breeze down` command
for user."""
+ if backend not in ["postgres", "mysql"] or os.environ.get("CI") == "true":
+ return
+
+ if _is_backend_container_unhealthy(project_name, backend):
+ get_console(output=output).print(
+ "[warning]The backend container is unhealthy. You might need to
run `down` "
+ "command to clean up:\n\n"
+ "\tbreeze down[/]\n"
+ )
+
+
+def _is_backend_container_unhealthy(project_name: str, backend: str) -> bool:
+ try:
+ filter = f"name={project_name}-{backend}"
+ search_response = run_command(
+ ["docker", "ps", "--filter", filter, "--format={{.Names}}"],
+ capture_output=True,
+ check=False,
+ text=True,
+ )
+ container_name = search_response.stdout.strip()
+
+ # Skip the check if not found or multiple containers found
+ if len(container_name.strip().splitlines()) != 1:
+ return False
+
+ inspect_response = run_command(
+ ["docker", "inspect", "--format={{.State.Health.Status}}",
container_name],
+ capture_output=True,
+ check=False,
+ text=True,
+ )
+ if inspect_response.returncode == 0:
+ return inspect_response.stdout.strip() == "unhealthy"
+ # We don't want to misguide the user, so in case of any error we skip the
check
Review Comment:
Nice, yeah. Good call! Peoeple are using podman, orbstack and others and
they might have some deviations from tooling
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]