Skip to content

Commit

Permalink
add retry option on bootstrap destroy, increase retries by one, enabl…
Browse files Browse the repository at this point in the history
…e retry in scenarios
  • Loading branch information
cwensel committed Aug 4, 2023
1 parent 3bc76e8 commit eeef832
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class BootstrapCommandOptions extends CommonCommandOptions {
)
boolean synth = false;

@CommandLine.Option(
names = "--retry",
description = "retry the destroy operation")
private boolean retry = false;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@CommandLine.Option(
names = "--approve",
Expand Down Expand Up @@ -77,4 +82,9 @@ public boolean synth() {
public Optional<Boolean> approve() {
return approve;
}

public boolean retry() {
// only enable retry if destroy is enabled
return destroy && retry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ protected int executeProcess(Map<String, String> environment, List<String> args)
LOG.warn("got exit code: {}, for command: {}, retrying in 15 seconds", exitCode, args);
Thread.sleep(15 * 1000);
exitCode = process(environment, args);

if (retry() && exitCode != 0) {
LOG.warn("got exit code: {}, for command: {}, retrying in 30 seconds", exitCode, args);
Thread.sleep(30 * 1000);
exitCode = process(environment, args);
}
}

return exitCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protected void createCommand(List<String> args) {
"--stage",
placement.get("stage"),
"-v",
destroy ? "--destroy" : null
destroy ? "--destroy" : null,
destroy ? "--retry" : null
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Bootstrap extends CDKCommand implements Callable<Integer> {
@CommandLine.Mixin
BootstrapCommandOptions commandOptions = new BootstrapCommandOptions();
@CommandLine.Mixin
CDKProcessExec processExec = new CDKProcessExec(commandOptions);
CDKProcessExec processExec = new CDKProcessExec(commandOptions::dryRun, commandOptions::retry);

@Override
public Integer call() throws Exception {
Expand Down

0 comments on commit eeef832

Please sign in to comment.