Skip to content

Commit

Permalink
Merge pull request #968 from snowflakedb/mayang-create_check_inverval…
Browse files Browse the repository at this point in the history
…_min_config

JENKINS-73096 Create config for check interval and use the same default
  • Loading branch information
res0nance authored May 20, 2024
2 parents 5526a2c + 438d256 commit 02b9b26
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/hudson/plugins/ec2/EC2RetentionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class EC2RetentionStrategy extends RetentionStrategy<EC2Computer> impleme
private transient ReentrantLock checkLock;
private static final int STARTUP_TIME_DEFAULT_VALUE = 30;

private static final Integer CHECK_INTERVAL_MINUTES = Integer.getInteger("jenkins.ec2.checkIntervalMinutes", 1);

@DataBoundConstructor
public EC2RetentionStrategy(String idleTerminationMinutes) {
readResolve();
Expand Down Expand Up @@ -99,7 +101,7 @@ long getNextCheckAfter() {
@Override
public long check(EC2Computer c) {
if (!checkLock.tryLock()) {
return 1;
return CHECK_INTERVAL_MINUTES;
} else {
try {
long currentTime = this.clock.millis();
Expand All @@ -109,7 +111,7 @@ public long check(EC2Computer c) {
nextCheckAfter = currentTime + TimeUnit.MINUTES.toMillis(intervalMins);
return intervalMins;
} else {
return 1;
return CHECK_INTERVAL_MINUTES;
}
} finally {
checkLock.unlock();
Expand All @@ -122,7 +124,7 @@ private long internalCheck(EC2Computer computer) {
* If we've been told never to terminate, or node is null(deleted), no checks to perform
*/
if (idleTerminationMinutes == 0 || computer.getNode() == null) {
return 1;
return CHECK_INTERVAL_MINUTES;
}

/*
Expand All @@ -134,7 +136,7 @@ private long internalCheck(EC2Computer computer) {
if (numberOfCurrentInstancesForTemplate > 0 && numberOfCurrentInstancesForTemplate <= slaveTemplate.getMinimumNumberOfInstances()) {
//Check if we're in an active time-range for keeping minimum number of instances
if (MinimumInstanceChecker.minimumInstancesActive(slaveTemplate.getMinimumNumberOfInstancesTimeRangeConfig())) {
return 1;
return CHECK_INTERVAL_MINUTES;
}
}
}
Expand All @@ -152,7 +154,7 @@ private long internalCheck(EC2Computer computer) {
// We'll just retry next time we test for idleness.
LOGGER.fine("Exception while checking host uptime for " + computer.getName()
+ ", will retry next check. Exception: " + e);
return 1;
return CHECK_INTERVAL_MINUTES;
}

//Don't bother checking anything else if the instance is already in the desired state:
Expand All @@ -164,7 +166,7 @@ private long internalCheck(EC2Computer computer) {
LOGGER.info("External Stop of " + computer.getName() + " detected - disconnecting. instance status" + state.toString());
computer.disconnect(null);
}
return 1;
return CHECK_INTERVAL_MINUTES;
}

//on rare occasions, AWS may return fault instance which shows running in AWS console but can not be connected.
Expand All @@ -177,7 +179,7 @@ private long internalCheck(EC2Computer computer) {

EC2AbstractSlave node = computer.getNode();
if (Objects.isNull(node)) {
return 1;
return CHECK_INTERVAL_MINUTES;
}
long launchTimeout = node.getLaunchTimeoutInMillis();
if (launchTimeout > 0 && uptime > launchTimeout) {
Expand All @@ -187,7 +189,7 @@ private long internalCheck(EC2Computer computer) {
" milliseconds (timeout: " + launchTimeout + " milliseconds), instance status: " + state.toString());
node.launchTimeout();
}
return 1;
return CHECK_INTERVAL_MINUTES;
} else {
LOGGER.log(Level.FINE, "Computer {0} offline but not connecting, will check if it should be terminated because of the idle time configured", computer.getInstanceId());
}
Expand Down Expand Up @@ -232,7 +234,7 @@ private long internalCheck(EC2Computer computer) {
}
}
}
return 1;
return CHECK_INTERVAL_MINUTES;
}

/*
Expand Down

0 comments on commit 02b9b26

Please sign in to comment.