Skip to content

Commit ce11e28

Browse files
feat: reuse wait logic from RequestHelper
There is common logic to wait for given resource status, this commit leverages that instead of custom logic for CE deletion.
1 parent 0d2f42c commit ce11e28

3 files changed

Lines changed: 17 additions & 29 deletions

File tree

src/main/java/io/seqera/tower/cli/commands/computeenvs/DeleteCmd.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.Collections;
3131
import java.util.concurrent.TimeUnit;
3232

33+
import static io.seqera.tower.cli.utils.ResponseHelper.waitStatus;
34+
3335
@Command(
3436
name = "delete",
3537
description = "Delete a compute environment."
@@ -64,7 +66,7 @@ protected Response exec() throws ApiException {
6466
computeEnvsApi().deleteComputeEnv(id, wspId, null);
6567
deletedId = id;
6668
deletedWspId = wspId;
67-
return new ComputeEnvDeleted(id, workspaceRef(wspId));
69+
return new ComputeEnvDeleted(id, workspaceRef(wspId), wspId);
6870
} catch (ApiException e) {
6971
if (e.getCode() == 403) {
7072
// Customize the forbidden message
@@ -80,34 +82,18 @@ protected Integer onBeforeExit(int exitCode, Response response) {
8082
return exitCode;
8183
}
8284

85+
ComputeEnvDeleted computeEnv = (ComputeEnvDeleted) response;
8386
boolean showProgress = app().output != OutputType.json;
8487

8588
try {
86-
long sleepMillis = 2000;
87-
while (true) {
88-
ComputeEnvStatus status = checkComputeEnvStatus(deletedId, deletedWspId);
89-
90-
if (status == null) {
91-
// CE is gone (404) - deletion succeeded
92-
if (showProgress) {
93-
app().getOut().println();
94-
}
95-
return CommandLine.ExitCode.OK;
96-
}
97-
98-
if (status == ComputeEnvStatus.ERRORED) {
99-
app().getErr().println("ERROR: Compute environment disposal failed (status: ERRORED). AWS resources may not have been cleaned up.");
100-
return CommandLine.ExitCode.SOFTWARE;
101-
}
102-
103-
if (showProgress) {
104-
app().getOut().print(".");
105-
app().getOut().flush();
106-
}
107-
108-
TimeUnit.MILLISECONDS.sleep(sleepMillis);
109-
sleepMillis = Math.min(sleepMillis + 1000, 120_000);
110-
}
89+
return waitStatus(
90+
app().getOut(),
91+
showProgress,
92+
ComputeEnvStatus.DELETED,
93+
ComputeEnvStatus.values(),
94+
() -> checkComputeEnvStatus(computeEnv.id, computeEnv.workspaceId),
95+
ComputeEnvStatus.ERRORED, ComputeEnvStatus.INVALID
96+
);
11197
} catch (InterruptedException e) {
11298
Thread.currentThread().interrupt();
11399
return exitCode;

src/main/java/io/seqera/tower/cli/responses/computeenvs/ComputeEnvDeleted.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ public class ComputeEnvDeleted extends Response {
2222

2323
public final String id;
2424
public final String workspaceRef;
25+
public final Long workspaceId;
2526

26-
public ComputeEnvDeleted(String id, String workspaceRef) {
27+
public ComputeEnvDeleted(String id, String workspaceRef, Long workspaceId) {
2728
this.id = id;
29+
this.workspaceId = workspaceId;
2830
this.workspaceRef = workspaceRef;
2931
}
3032

src/test/java/io/seqera/tower/cli/computeenvs/ComputeEnvsCmdTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void testDelete(OutputType format, MockServerClient mock) {
7676
);
7777

7878
ExecOut out = exec(format, mock, "compute-envs", "delete", "-i", "vYOK4vn7spw7bHHWBDXZ2");
79-
assertOutput(format, out, new ComputeEnvDeleted("vYOK4vn7spw7bHHWBDXZ2", USER_WORKSPACE_NAME));
79+
assertOutput(format, out, new ComputeEnvDeleted("vYOK4vn7spw7bHHWBDXZ2", USER_WORKSPACE_NAME, null));
8080
}
8181

8282
@Test
@@ -733,7 +733,7 @@ void testDeleteWaitHappyPath(MockServerClient mock) {
733733
mock.when(
734734
request().withMethod("GET").withPath("/compute-envs/vYOK4vn7spw7bHHWBDXZ2"), exactly(1)
735735
).respond(
736-
response().withStatusCode(404)
736+
response().withStatusCode(200).withBody("{\"computeEnv\":{\"id\":\"vYOK4vn7spw7bHHWBDXZ2\",\"name\":\"demo\",\"platform\":\"aws-batch\",\"status\":\"DELETED\"}}").withContentType(MediaType.APPLICATION_JSON)
737737
);
738738

739739
ExecOut out = exec(mock, "compute-envs", "delete", "-i", "vYOK4vn7spw7bHHWBDXZ2", "--wait");

0 commit comments

Comments
 (0)