def wait_for_health()

in project/alcatraz/alcatraz/clusters/local.py [0:0]


    def wait_for_health(self, container_id: str) -> bool:
        """Wait for a Docker container to be healthy.

        Args:
            container_id (str): ID of the container.

        Returns:
            bool: True if the container is healthy, False if not or if 60s timeout occurred
        """
        start_time = time.monotonic()

        while time.monotonic() - start_time < 60:
            container = self.docker_client.containers.get(container_id)
            attrs = cast(Any, container.attrs)
            if "Health" not in attrs["State"]:
                logger.warning("Container health not available for this container, ignoring.")
                return True
            status = attrs["State"]["Health"]["Status"]
            if status == "healthy":
                return True
            elif status == "unhealthy":
                print("Container became unhealthy.")
                return False
            time.sleep(0.2)  # Check every 10 seconds

        print("Timeout reached without becoming healthy.")
        return False