From 694a5f2a9146544c7ee659d03d985f68bd7fc458 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 18 Jul 2024 14:01:24 +0800 Subject: [PATCH] feat: change spinner text on status change and show spinner after image build done (#4867) Signed-off-by: Frost Ming --- src/bentoml/_internal/cloud/deployment.py | 35 +++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/bentoml/_internal/cloud/deployment.py b/src/bentoml/_internal/cloud/deployment.py index e7cf302d9dd..2c878b670c9 100644 --- a/src/bentoml/_internal/cloud/deployment.py +++ b/src/bentoml/_internal/cloud/deployment.py @@ -560,26 +560,37 @@ def tail_image_builder_logs() -> None: while time.time() - start_time < timeout: for _ in range(3): try: - status = self.get_status() + new_status = self.get_status() break except TimeoutException: spinner.update( "⚠️ Unable to get deployment status, retrying..." ) - if status is None: + else: spinner.log( - "🚨 [bold red]Unable to contact the server, but the deployment is created. You can check the status on the bentocloud website.[/bold red]" + "🚨 [bold red]Unable to contact the server, but the deployment is created. " + "You can check the status on the bentocloud website.[/bold red]" ) return - spinner.update( - f'🔄 Waiting for deployment "{self.name}" to be ready. Current status: "{status.status}"' - ) - if status.status == DeploymentStatus.ImageBuilding.value: - if tail_thread is None: - tail_thread = Thread( - target=tail_image_builder_logs, daemon=True - ) - tail_thread.start() + if ( + status is None or status.status != new_status.status + ): # on status change + status = new_status + spinner.update( + f'🔄 Waiting for deployment "{self.name}" to be ready. Current status: "{status.status}"' + ) + if status.status == DeploymentStatus.ImageBuilding.value: + if tail_thread is None: + tail_thread = Thread( + target=tail_image_builder_logs, daemon=True + ) + tail_thread.start() + elif ( + tail_thread is not None + ): # The status has changed from ImageBuilding to other + stop_tail_event.set() + tail_thread.join() + spinner.start() if status.status in ( DeploymentStatus.Running.value,