Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client side options for changing retry behaviour #4

Merged
merged 1 commit into from Jul 31, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions client/src/main/java/hudson/plugins/swarm/Client.java
Expand Up @@ -76,6 +76,12 @@ public class Client {
@Option(name = "-disableSslVerification", usage = "Disables SSL verification in the HttpClient.")
public boolean disableSslVerification;

@Option(name = "-noRetryAfterConnected", usage = "Do not retry if a successful connection gets closed.")
public boolean noRetryAfterConnected;

@Option(name = "-retry", usage = "Number of retries before giving up. Unlimited if not specified.")
public int retry = -1;

@Option(
name = "-mode",
usage = "The mode controlling how Jenkins allocates jobs to slaves. Can be either '" + ModeOptionHandler.NORMAL + "' " +
Expand Down Expand Up @@ -154,6 +160,10 @@ public void run() throws InterruptedException {
// create a new swarm slave
createSwarmSlave();
connect();
if (noRetryAfterConnected) {
System.out.println("Connection closed, exiting...");
System.exit(0);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
Expand All @@ -165,6 +175,16 @@ public void run() throws InterruptedException {
}
}

if (retry >= 0) {
if (retry == 0) {
System.out.println("Retry limit reached, exiting...");
System.exit(-1);
} else {
System.out.println("Remaining retries: " + retry);
retry--;
}
}

// retry
System.out.println("Retrying in 10 seconds");
Thread.sleep(10 * 1000);
Expand Down