Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(retry-scheduling) Retry logic when scheduling is not accepted #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.queue.CauseOfBlockage;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
Expand All @@ -24,8 +26,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.TreeSet;
import javax.annotation.Nullable;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* {@link MatrixExecutionStrategy} that captures historical behavior.
Expand Down Expand Up @@ -233,18 +233,31 @@ private <T> TreeSet<T> createTreeSet(Collection<T> items, Comparator<T> sorter)
*
* This function schedule a build of a configuration passing all of the Matrixchild actions
* that are present in the parent build.
* If scheduling the build in the queue fails, it will retry 5 times and wait 1/2 seconds
* before retrying.
*
* @param exec Matrix build that is the parent of the configuration
* @param c Configuration to schedule
*/
private void scheduleConfigurationBuild(MatrixBuildExecution exec, MatrixConfiguration c) {
MatrixBuild build = exec.getBuild();
exec.getListener().getLogger().println(Messages.MatrixBuild_Triggering(ModelHyperlinkNote.encodeTo(c)));

// filter the parent actions for those that can be passed to the individual jobs.
List<Action> childActions = new ArrayList<Action>(build.getActions(MatrixChildAction.class));
childActions.addAll(build.getActions(ParametersAction.class)); // used to implement MatrixChildAction
c.scheduleBuild(childActions, new UpstreamCause((Run)build));
Boolean scheduled;
int retry = 5;
for(int i=0; i < retry; i++) {
exec.getListener().getLogger().println(Messages.MatrixBuild_Triggering(ModelHyperlinkNote.encodeTo(c)));
scheduled = c.scheduleBuild(childActions, new UpstreamCause((Run) build));
if(scheduled == true) {
break;
}
try {
Thread.sleep(500);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}

private MatrixRun waitForCompletion(MatrixBuildExecution exec, MatrixConfiguration c) throws InterruptedException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,10 @@
*/
package hudson.matrix;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import hudson.ExtensionList;
import hudson.matrix.MatrixBuild.MatrixBuildExecution;
import hudson.matrix.listeners.MatrixBuildListener;
import hudson.model.AbstractItem;
import hudson.model.BuildListener;
import hudson.model.Cause;
import hudson.model.ParametersAction;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StringParameterValue;

import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import hudson.model.*;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.BlanketWhitelist;
Expand All @@ -65,6 +42,14 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.io.IOException;
import java.io.PrintStream;
import java.util.*;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;

/**
* Make sure that the combination filter schedules correct builds in correct order
*
Expand Down Expand Up @@ -270,6 +255,7 @@ private MatrixConfiguration getConfiguration (final String axis) {
when(conf.getDisplayName()).thenReturn(axis);
when(conf.getUrl()).thenReturn(axis);
when(conf.getBuildByNumber(anyInt())).thenReturn(run);
when(conf.scheduleBuild(anyList(),any())).thenReturn(true);

return conf;
}
Expand Down