Skip to content

Commit

Permalink
Merge pull request #126 from jenkinsci/jenkins-42254
Browse files Browse the repository at this point in the history
[JENKINS-42254] Make the github sync delay configurable
  • Loading branch information
stephenc committed Mar 8, 2017
2 parents f7546e3 + 92e38ad commit 5273e4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Expand Up @@ -129,6 +129,11 @@ public class GitHubSCMSource extends AbstractGitSCMSource {
*/
// TODO remove once baseline Git plugin 3.0.2+
private static final AtomicLong jenkins41244Warning = new AtomicLong();
/**
* How long to delay events received from GitHub in order to allow the API caches to sync.
*/
private static /*mostly final*/ int eventDelaySeconds =
Math.min(300, Math.max(0, Integer.getInteger(GitHubSCMSource.class.getName() + ".eventDelaySeconds", 5)));

private final String apiUri;

Expand Down Expand Up @@ -235,6 +240,26 @@ private Object readResolve() {
return this;
}

/**
* Returns how long to delay events received from GitHub in order to allow the API caches to sync.
*
* @return how long to delay events received from GitHub in order to allow the API caches to sync.
*/
public static int getEventDelaySeconds() {
return eventDelaySeconds;
}

/**
* Sets how long to delay events received from GitHub in order to allow the API caches to sync.
*
* @param eventDelaySeconds number of seconds to delay, will be restricted into a value within the range
* {@code [0,300]} inclusive
*/
@Restricted(NoExternalUse.class) // to allow configuration from system groovy console
public static void setEventDelaySeconds(int eventDelaySeconds) {
GitHubSCMSource.eventDelaySeconds = Math.min(300, Math.max(0, eventDelaySeconds));
}

@CheckForNull
public String getApiUri() {
return apiUri;
Expand Down
Expand Up @@ -156,12 +156,7 @@ protected void onEvent(GHSubscriberEvent event) {
}

private void fireAfterDelay(final SCMHeadEventImpl e) {
Timer.get().schedule(new Runnable() {
@Override
public void run() {
SCMHeadEvent.fireNow(e);
}
}, 5, TimeUnit.SECONDS);
SCMHeadEvent.fireLater(e, GitHubSCMSource.getEventDelaySeconds(), TimeUnit.SECONDS);
}

private static class SCMHeadEventImpl extends SCMHeadEvent<GHEventPayload.PullRequest> {
Expand Down
Expand Up @@ -155,12 +155,7 @@ protected void onEvent(GHSubscriberEvent event) {
}

private void fireAfterDelay(final SCMHeadEventImpl e) {
Timer.get().schedule(new Runnable() {
@Override
public void run() {
SCMHeadEvent.fireNow(e);
}
}, 5, TimeUnit.SECONDS);
SCMHeadEvent.fireLater(e, GitHubSCMSource.getEventDelaySeconds(), TimeUnit.SECONDS);
}

private static class SCMHeadEventImpl extends SCMHeadEvent<GHEventPayload.Push> {
Expand Down

0 comments on commit 5273e4f

Please sign in to comment.