Search in sources :

Example 1 with ScriptJobResolver

use of org.craftercms.engine.scripting.ScriptJobResolver in project engine by craftercms.

the class SiteContextFactory method scheduleJobs.

protected Scheduler scheduleJobs(SiteContext siteContext) {
    String siteName = siteContext.getSiteName();
    logger.info("--------------------------------------------------");
    logger.info("<Scheduling job scripts for site: " + siteName + ">");
    logger.info("--------------------------------------------------");
    try {
        List<JobContext> allJobContexts = new ArrayList<>();
        for (ScriptJobResolver jobResolver : jobResolvers) {
            List<JobContext> jobContexts = jobResolver.resolveJobs(siteContext);
            if (CollectionUtils.isNotEmpty(jobContexts)) {
                allJobContexts.addAll(jobContexts);
            }
        }
        if (CollectionUtils.isNotEmpty(allJobContexts)) {
            Scheduler scheduler = SchedulingUtils.createScheduler(String.format("%s_%s_scheduler", siteName, siteContext.getContext().getId()), jobThreadPoolExecutor);
            for (JobContext jobContext : allJobContexts) {
                scheduler.scheduleJob(jobContext.getDetail(), jobContext.getTrigger());
                logger.info("Scheduled job: " + jobContext + " for site '" + siteName + "'");
            }
            scheduler.start();
            return scheduler;
        }
    } catch (Exception e) {
        logger.error("Unable to schedule jobs for site '" + siteName + "'", e);
    } finally {
        logger.info("--------------------------------------------------");
        logger.info("</Scheduling job scripts for site: " + siteName + ">");
        logger.info("--------------------------------------------------");
    }
    return null;
}
Also used : Scheduler(org.quartz.Scheduler) ScriptJobResolver(org.craftercms.engine.scripting.ScriptJobResolver) JobContext(org.craftercms.engine.util.quartz.JobContext) SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) ConfigurationException(org.craftercms.commons.config.ConfigurationException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ConfigurationException (org.craftercms.commons.config.ConfigurationException)1 SiteContextCreationException (org.craftercms.engine.exception.SiteContextCreationException)1 ScriptJobResolver (org.craftercms.engine.scripting.ScriptJobResolver)1 JobContext (org.craftercms.engine.util.quartz.JobContext)1 Scheduler (org.quartz.Scheduler)1 BeansException (org.springframework.beans.BeansException)1