use of org.craftercms.engine.util.quartz.JobContext in project engine by craftercms.
the class SchedulingUtils method createJobContext.
public static JobContext createJobContext(SiteContext siteContext, String scriptUrl, String cronExpression, ServletContext servletContext) {
String jobName = siteContext.getSiteName() + ":" + scriptUrl;
JobDetail detail = SchedulingUtils.createScriptJob(siteContext, jobName, scriptUrl, servletContext);
Trigger trigger = SchedulingUtils.createCronTrigger("trigger for " + jobName, cronExpression);
String description = "Job{url='" + scriptUrl + "', cron='" + cronExpression + "'}";
return new JobContext(detail, trigger, description);
}
use of org.craftercms.engine.util.quartz.JobContext in project engine by craftercms.
the class ConfigurationScriptJobResolver method resolveJobs.
@Override
@SuppressWarnings("unchecked")
public List<JobContext> resolveJobs(SiteContext siteContext) throws SchedulingException {
HierarchicalConfiguration config = siteContext.getConfig();
List<JobContext> jobContexts = new ArrayList<>();
if (config != null) {
List<HierarchicalConfiguration> jobFoldersConfig = config.configurationsAt(JOB_FOLDER_KEY);
if (CollectionUtils.isNotEmpty(jobFoldersConfig)) {
for (HierarchicalConfiguration jobFolderConfig : jobFoldersConfig) {
List<JobContext> folderJobContexts = getJobsUnderFolder(siteContext, jobFolderConfig);
if (CollectionUtils.isNotEmpty(folderJobContexts)) {
jobContexts.addAll(folderJobContexts);
}
}
}
List<HierarchicalConfiguration> jobsConfig = config.configurationsAt(JOB_KEY);
if (CollectionUtils.isNotEmpty(jobsConfig)) {
for (HierarchicalConfiguration jobConfig : jobsConfig) {
JobContext jobContext = getJob(siteContext, jobConfig);
if (jobContext != null) {
jobContexts.add(jobContext);
}
}
}
}
return jobContexts;
}
use of org.craftercms.engine.util.quartz.JobContext in project engine by craftercms.
the class ConfigurationScriptJobResolver method getJobsUnderFolder.
protected List<JobContext> getJobsUnderFolder(SiteContext siteContext, HierarchicalConfiguration jobFolderConfig) {
List<JobContext> jobContexts = null;
String folderPath = jobFolderConfig.getString(PATH_KEY);
String cronExpression = jobFolderConfig.getString(CRON_EXPRESSION_KEY);
ContentStoreService storeService = siteContext.getStoreService();
Context context = siteContext.getContext();
if (StringUtils.isNotEmpty(folderPath) && StringUtils.isNotEmpty(cronExpression)) {
List<String> scriptPaths = ContentStoreUtils.findChildrenUrl(storeService, context, folderPath);
if (CollectionUtils.isNotEmpty(scriptPaths)) {
for (String scriptPath : scriptPaths) {
if (scriptPath.endsWith(scriptSuffix)) {
if (jobContexts == null) {
jobContexts = new ArrayList<>();
}
jobContexts.add(SchedulingUtils.createJobContext(siteContext, scriptPath, cronExpression, disableVariableRestrictions ? servletContext : null));
}
}
}
}
return jobContexts;
}
use of org.craftercms.engine.util.quartz.JobContext in project engine by craftercms.
the class ConfigurationScriptJobResolverTest method testResolveJobs.
@Test
public void testResolveJobs() throws Exception {
List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
assertNotNull(jobContexts);
assertEquals(2, jobContexts.size());
JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
assertEquals(ScriptJob.class, jobDetail.getJobClass());
assertEquals("/scripts/jobs/morejobs/testJob2.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
jobDetail = (JobDetailImpl) jobContexts.get(1).getDetail();
trigger = (CronTrigger) jobContexts.get(1).getTrigger();
assertEquals(ScriptJob.class, jobDetail.getJobClass());
assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
}
use of org.craftercms.engine.util.quartz.JobContext in project engine by craftercms.
the class FolderBasedScriptJobResolverTest method testResolveJobs.
@Test
public void testResolveJobs() throws Exception {
List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
assertNotNull(jobContexts);
assertEquals(1, jobContexts.size());
JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
assertEquals(ScriptJob.class, jobDetail.getJobClass());
assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
assertEquals(HOURLY_CRON_EXPRESSION, trigger.getCronExpression());
}
Aggregations