Skip to content
Permalink
Browse files

[FIXED JENKINS-43424] Introduce entropy into the periodic folder trig…

…ger for short intervals
  • Loading branch information...
stephenc committed Apr 7, 2017
1 parent 806efc0 commit c0fcee5ae58d67b227e76b21fc887d73a50ed428
@@ -33,8 +33,11 @@
import hudson.triggers.TriggerDescriptor;
import hudson.util.ListBoxModel;
import hudson.util.TimeUnit2;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

@@ -48,6 +51,11 @@

private static final Logger LOGGER = Logger.getLogger(PeriodicFolderTrigger.class.getName());

/**
* Captures the time that this class was loaded.
*/
private static final long startup = System.currentTimeMillis();

/**
* The interval between successive indexings.
*/
@@ -85,13 +93,13 @@ private static String toCrontab(String interval) {
return "* * * * *";
}
if (millis < TimeUnit2.MINUTES.toMillis(10)) {
return "*/12 * * * *";
return "H/12 * * * *";
}
if (millis < TimeUnit2.MINUTES.toMillis(30)) {
return "*/6 * * * *";
return "H/6 * * * *";
}
if (millis < TimeUnit2.HOURS.toMillis(1)) {
return "*/2 * * * *";
return "H/2 * * * *";
}
if (millis < TimeUnit2.HOURS.toMillis(8)) {
return "H * * * *";
@@ -183,7 +191,14 @@ public void run() {
return;
}
}
if (now - lastTriggered < interval) {
if (lastTriggered == 0) {
// on start-up set the last triggered to sometime within the interval of start-up
// for short intervals this will have no effect
// for longer intervals this will stagger all the computations on start-up
// when creating new instances this will be ignored as the computation result will be null
lastTriggered = startup + new Random().nextInt((int)Math.min(TimeUnit.DAYS.toMillis(1), interval));
}
if (now - lastTriggered < interval && (computation != null && computation.getResult() != null)) {
LOGGER.log(Level.FINE, "Too early to reschedule {0} based on last triggering", job);
return;
}

0 comments on commit c0fcee5

Please sign in to comment.
You can’t perform that action at this time.