mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 12:02:20 +00:00
Issue number: 806
Provide synchronous SCM polling in the order of dependencies. For now, to activate, edit hudson.triggers.SCMTrigger.xml and add <synchronousPolling>true</synchronousPolling> This change also relaxes visibility of Trigger.run() from protected to public. TODO: connect the UI and provide a global crontab spec setting. This will probably happen when I get some feedback on this change. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4700 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
47deb5958b
commit
b40c6a556c
5 files changed
+117
-21
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package hudson;
|
||||
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.Hudson;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Runs a job on all projects in the order of dependencies
|
||||
*/
|
||||
public class DependencyRunner implements Runnable {
|
||||
AbstractProject currentProject;
|
||||
|
||||
ProjectRunnable runnable;
|
||||
|
||||
List<AbstractProject> polledProjects = new ArrayList<AbstractProject>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public DependencyRunner(ProjectRunnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Set<AbstractProject> topLevelProjects = new HashSet<AbstractProject>();
|
||||
// Get all top-level projects
|
||||
for (AbstractProject p : Hudson.getInstance().getAllItems(
|
||||
AbstractProject.class))
|
||||
if (p.getUpstreamProjects().size() == 0)
|
||||
topLevelProjects.add(p);
|
||||
populate(topLevelProjects);
|
||||
for (AbstractProject p : polledProjects)
|
||||
runnable.run(p);
|
||||
}
|
||||
|
||||
private void populate(Set<AbstractProject> projectList) {
|
||||
for (AbstractProject p : projectList) {
|
||||
if (polledProjects.contains(p))
|
||||
// Project will be readded at the queue, so that we always use
|
||||
// the longest path
|
||||
polledProjects.remove(p);
|
||||
|
||||
polledProjects.add(p);
|
||||
|
||||
// Add all downstream dependencies
|
||||
populate(new HashSet<AbstractProject>(p.getDownstreamProjects()));
|
||||
}
|
||||
}
|
||||
|
||||
public interface ProjectRunnable {
|
||||
void run(AbstractProject p);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user