Skip to content

Commit 0a11fb7

Browse files
car-rollcar-rollres0nance
authored
reconnect when agent is offline (#1142)
* reconnect when agent is offline * address comments * move offline check --------- Co-authored-by: car-roll <[email protected]> Co-authored-by: Raihaan Shouhell <[email protected]>
1 parent 804c487 commit 0a11fb7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public long check(EC2Computer c) {
103103
long currentTime = this.clock.millis();
104104

105105
if (currentTime > nextCheckAfter) {
106+
attemptReconnectIfOffline(c);
106107
long intervalMins = internalCheck(c);
107108
nextCheckAfter = currentTime + TimeUnit.MINUTES.toMillis(intervalMins);
108109
return intervalMins;
@@ -248,6 +249,17 @@ private long internalCheck(EC2Computer computer) {
248249
return CHECK_INTERVAL_MINUTES;
249250
}
250251

252+
private void attemptReconnectIfOffline(EC2Computer computer) {
253+
if (computer.isOffline()) {
254+
LOGGER.warning("EC2Computer " + computer.getName() + " is offline");
255+
if (!computer.isConnecting()) {
256+
// Keep retrying connection to agent until the job times out
257+
LOGGER.warning("Attempting to reconnect EC2Computer " + computer.getName());
258+
computer.connect(false);
259+
}
260+
}
261+
}
262+
251263
/*
252264
* Checks if there are any items in the queue that are waiting for this node explicitly.
253265
* This prevents a node from being taken offline while there are Ivy/Maven Modules waiting to build.

0 commit comments

Comments
 (0)