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;
}
Aggregations