Search in sources :

Example 1 with DependencyRunner

use of hudson.DependencyRunner in project hudson-2.x by hudson.

the class Trigger method checkTriggers.

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)) {
                    LOGGER.config("cron triggered " + p.getName());
                    try {
                        t.run();
                    } catch (Throwable e) {
                        // t.run() is a plugin, and some of them throw RuntimeException and other things.
                        // don't let that cancel the polling activity. report and move on.
                        LOGGER.log(Level.WARNING, t.getClass().getName() + ".run() failed for " + p.getName(), e);
                    }
                }
            }
        }
    }
}
Also used : DependencyRunner(hudson.DependencyRunner) Hudson(hudson.model.Hudson) ProjectRunnable(hudson.DependencyRunner.ProjectRunnable) AbstractProject(hudson.model.AbstractProject)

Aggregations

DependencyRunner (hudson.DependencyRunner)1 ProjectRunnable (hudson.DependencyRunner.ProjectRunnable)1 AbstractProject (hudson.model.AbstractProject)1 Hudson (hudson.model.Hudson)1