}
private static Future previousSynchronousPolling;
public static void checkTriggers(final Calendar cal) {
Hudson inst = Hudson.getInstance();
// Are we using synchronous polling?
SCMTrigger.DescriptorImpl scmd = inst.getDescriptorByType(SCMTrigger.DescriptorImpl.class);
if (scmd.synchronousPolling) {
LOGGER.fine("using synchronous polling");
// Check that previous synchronous polling job is done to prevent piling up too many jobs
if (previousSynchronousPolling == null || previousSynchronousPolling.isDone()) {
// Process SCMTriggers in the order of dependencies. Note that the crontab spec expressed per-project is
// ignored, only the global setting is honored. The polling job is submitted only if the previous job has
// terminated.
// FIXME allow to set a global crontab spec
previousSynchronousPolling = scmd.getExecutor().submit(new DependencyRunner(new ProjectRunnable() {
public void run(AbstractProject p) {
for (Trigger t : (Collection<Trigger>) p.getTriggers().values()) {
if (t instanceof SCMTrigger) {
LOGGER.fine("synchronously triggering SCMTrigger for project " + t.job.getName());
t.run();
}
}
}
}));
} else {
LOGGER.fine("synchronous polling has detected unfinished jobs, will not trigger additional jobs.");
}
}
// Process all triggers, except SCMTriggers when synchronousPolling is set
for (AbstractProject<?,?> p : inst.getAllItems(AbstractProject.class)) {
for (Trigger t : p.getTriggers().values()) {
if (! (t instanceof SCMTrigger && scmd.synchronousPolling)) {
LOGGER.fine("cron checking "+p.getName());
if (t.tabs.check(cal)) {