diff --git a/README.md b/README.md index e60a4f8c..f23cb905 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ credentials: - On every agent provisioned by the plugin, there is an environment variable `OPENSTACK_PUBLIC_IP` declared with the public IP address allocated for the machine. +- Default recurrence period for thread cleaning up agents is 10 minutes, for thread pre-creating node it is 2 minutes. These values can be modified by setting new values in milliseconds in system properties `jenkins.openstack.cleanupPeriod` and `jenkins.openstack.preCreationPeriod`. This is particularly useful in combinations with single-use agents (agents with 1 executor and retention time set to `0`) for Jenkins installation with quick and often executed jobs. ### Troubleshooting diff --git a/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsCleanupThread.java b/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsCleanupThread.java index d6fbcb7b..997358a2 100644 --- a/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsCleanupThread.java +++ b/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsCleanupThread.java @@ -26,6 +26,8 @@ import org.openstack4j.api.exceptions.ClientResponseException; import org.openstack4j.api.exceptions.StatusCode; import org.openstack4j.model.compute.Server; +import java.util.concurrent.TimeUnit; + import javax.annotation.Nonnull; @@ -41,14 +43,17 @@ @Extension @Restricted(NoExternalUse.class) public final class JCloudsCleanupThread extends AsyncPeriodicWork { private static final Logger LOGGER = Logger.getLogger(JCloudsCleanupThread.class.getName()); + private final Long recurrencePeriod; public JCloudsCleanupThread() { super("OpenStack slave cleanup"); + recurrencePeriod = Long.getLong("jenkins.openstack.cleanupPeriod", TimeUnit.MINUTES.toMillis(10)); + LOGGER.log(Level.FINE, "OpenStack cleanup recurrence period is {0}ms", recurrencePeriod); } @Override public long getRecurrencePeriod() { - return MIN * 10; + return recurrencePeriod; } @Override diff --git a/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsPreCreationThread.java b/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsPreCreationThread.java index 9fc3f54c..a796e077 100644 --- a/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsPreCreationThread.java +++ b/plugin/src/main/java/jenkins/plugins/openstack/compute/JCloudsPreCreationThread.java @@ -13,6 +13,8 @@ import hudson.Functions; import hudson.model.TaskListener; import hudson.model.AsyncPeriodicWork; +import java.util.concurrent.TimeUnit; + /** * Periodically ensure enough slaves are created. @@ -37,14 +39,17 @@ @Extension @Restricted(NoExternalUse.class) public final class JCloudsPreCreationThread extends AsyncPeriodicWork { private static final Logger LOGGER = Logger.getLogger(JCloudsPreCreationThread.class.getName()); + private final Long recurrencePeriod; public JCloudsPreCreationThread() { super("OpenStack slave pre-creation"); + recurrencePeriod = Functions.getIsUnitTest() ? Long.MAX_VALUE : Long.getLong("jenkins.openstack.preCreationPeriod", TimeUnit.MINUTES.toMillis(2)); + LOGGER.log(Level.FINE, "OpenStack pre-creation recurrence period is {0}ms", recurrencePeriod); } @Override public long getRecurrencePeriod() { - return Functions.getIsUnitTest() ? Long.MAX_VALUE : MIN * 2; + return recurrencePeriod; } @Override