Skip to content

Commit

Permalink
feat: option to wait for destroy job
Browse files Browse the repository at this point in the history
  • Loading branch information
parisk committed Nov 12, 2024
1 parent efd555b commit ca82b05
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cycleops/setups.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def destroy(
setup_identifier: str = typer.Argument(
..., help="The ID or name of the setup. Names take precedence."
),
wait: Optional[bool] = typer.Option(
default=False, help="Wait for the destroy job to complete"
),
) -> None:
"""
Destroy the setup with the specified given ID or name.
Expand All @@ -233,6 +236,34 @@ def destroy(
display_error_message(error)
raise typer.Abort()

destruction_scheduled_message = (
f"Setup {setup_identifier} has been queued for destruction"
)

if not wait:
display_success_message(destruction_scheduled_message)
return

print(f"{destruction_scheduled_message}\n")

try:
display_job_logs(job["id"])
except websockets.exceptions.ConnectionClosed:
job = job_client.retrieve(job["id"])

match job["status"]:
case "Destroyed":
display_success_message(
f"Setup {setup_identifier} has been destroyed successfully"
)
case "Failed":
display_error_message(
f"Setup {setup_identifier} could not be destroyed"
)
case _:
print(f"Setup {setup_identifier} is in status {job['status']}")
return


def get_setup(setup_identifier: str) -> Optional[Dict[str, Any]]:
"""
Expand Down

0 comments on commit ca82b05

Please sign in to comment.