Skip to content

Commit ca82b05

Browse files
committed
feat: option to wait for destroy job
1 parent efd555b commit ca82b05

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

cycleops/setups.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ def destroy(
219219
setup_identifier: str = typer.Argument(
220220
..., help="The ID or name of the setup. Names take precedence."
221221
),
222+
wait: Optional[bool] = typer.Option(
223+
default=False, help="Wait for the destroy job to complete"
224+
),
222225
) -> None:
223226
"""
224227
Destroy the setup with the specified given ID or name.
@@ -233,6 +236,34 @@ def destroy(
233236
display_error_message(error)
234237
raise typer.Abort()
235238

239+
destruction_scheduled_message = (
240+
f"Setup {setup_identifier} has been queued for destruction"
241+
)
242+
243+
if not wait:
244+
display_success_message(destruction_scheduled_message)
245+
return
246+
247+
print(f"{destruction_scheduled_message}\n")
248+
249+
try:
250+
display_job_logs(job["id"])
251+
except websockets.exceptions.ConnectionClosed:
252+
job = job_client.retrieve(job["id"])
253+
254+
match job["status"]:
255+
case "Destroyed":
256+
display_success_message(
257+
f"Setup {setup_identifier} has been destroyed successfully"
258+
)
259+
case "Failed":
260+
display_error_message(
261+
f"Setup {setup_identifier} could not be destroyed"
262+
)
263+
case _:
264+
print(f"Setup {setup_identifier} is in status {job['status']}")
265+
return
266+
236267

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

0 commit comments

Comments
 (0)