use of org.quartz.CronTrigger in project new-cloud by xie-summer.
the class BaseJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// 是否已执行业务逻辑
boolean isExecute = false;
// 业务逻辑执行后返回结果
boolean flag = false;
try {
// 可以通过context拿到执行当前任务的quartz中的很多信息,如当前是哪个trigger在执行该任务
CronTrigger trigger = (CronTrigger) context.getTrigger();
String corn = trigger.getCronExpression();
String jobName = trigger.getKey().getName();
String jobGroup = trigger.getKey().getGroup();
} catch (Exception e) {
}
}
use of org.quartz.CronTrigger in project zeppelin by apache.
the class QuartzSchedulerService method refreshCron.
@Override
public boolean refreshCron(String noteId) throws IOException {
removeCron(noteId);
return notebook.processNote(noteId, note -> {
if (note == null) {
LOGGER.warn("Skip refresh cron of note: {} because there's no such note", noteId);
return false;
}
if (note.isTrash()) {
LOGGER.warn("Skip refresh cron of note: {} because it is in trash", noteId);
return false;
}
Map<String, Object> config = note.getConfig();
if (config == null) {
LOGGER.warn("Skip refresh cron of note: {} because its config is empty.", noteId);
return false;
}
if (!note.isCronSupported(zeppelinConfiguration)) {
LOGGER.warn("Skip refresh cron of note {} because its cron is not enabled.", noteId);
return false;
}
String cronExpr = (String) note.getConfig().get("cron");
if (cronExpr == null || cronExpr.trim().length() == 0) {
LOGGER.warn("Skip refresh cron of note {} because its cron expression is empty.", noteId);
return false;
}
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("notebook", notebook);
jobDataMap.put("noteId", noteId);
JobDetail newJob = JobBuilder.newJob(CronJob.class).withIdentity(noteId, "note").setJobData(jobDataMap).build();
Map<String, Object> info = note.getInfo();
info.put("cron", null);
CronTrigger trigger = null;
try {
trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + noteId, "note").withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(noteId, "note").build();
} catch (Exception e) {
LOGGER.error("Fail to create cron trigger for note: {}", noteId, e);
info.put("cron", e.getMessage());
return false;
}
try {
LOGGER.info("Trigger cron for note: {}, with cron expression: {}", noteId, cronExpr);
scheduler.scheduleJob(newJob, trigger);
return true;
} catch (SchedulerException e) {
LOGGER.error("Fail to schedule cron job for note: {}", noteId, e);
info.put("cron", "Scheduler Exception");
return false;
}
});
}
use of org.quartz.CronTrigger in project SSM by Intel-bigdata.
the class Notebook method refreshCron.
public void refreshCron(String id) {
removeCron(id);
synchronized (notes) {
Note note = notes.get(id);
if (note == null) {
return;
}
Map<String, Object> config = note.getConfig();
if (config == null) {
return;
}
String cronExpr = (String) note.getConfig().get("cron");
if (cronExpr == null || cronExpr.trim().length() == 0) {
return;
}
JobDetail newJob = JobBuilder.newJob(CronJob.class).withIdentity(id, "note").usingJobData("noteId", id).build();
Map<String, Object> info = note.getInfo();
info.put("cron", null);
CronTrigger trigger = null;
try {
trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + id, "note").withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(id, "note").build();
} catch (Exception e) {
logger.error("Error", e);
info.put("cron", e.getMessage());
}
try {
if (trigger != null) {
quartzSched.scheduleJob(newJob, trigger);
}
} catch (SchedulerException e) {
logger.error("Error", e);
info.put("cron", "Scheduler Exception");
}
}
}
use of org.quartz.CronTrigger in project spring-framework by spring-projects.
the class CronTriggerFactoryBeanTests method createWithoutJobDetail.
@Test
public void createWithoutJobDetail() throws ParseException {
CronTriggerFactoryBean factory = new CronTriggerFactoryBean();
factory.setName("myTrigger");
factory.setCronExpression("0 15 10 ? * *");
factory.afterPropertiesSet();
CronTrigger trigger = factory.getObject();
assertThat(trigger.getCronExpression()).isEqualTo("0 15 10 ? * *");
}
use of org.quartz.CronTrigger in project alfresco-remote-api by Alfresco.
the class RepositoryContainerTest method testLargeContentRequest.
/*
* Test for MNT-11237 : CMIS uploading file larger the 4mb fails
*
* Tests that requests with content larger than 4mb (default memoryThreshold value) can be successfully handled by repository container
*/
public void testLargeContentRequest() throws Exception {
authenticationComponent.setCurrentUser(USER_ONE);
// create the 5 mb size buffer of zero bytes
byte[] content = new byte[5 * 1024 * 1024];
Arrays.fill(content, (byte) 0);
// chek that we can upload file larger than 4 mb
Response response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
assertEquals(SUCCESS, response.getContentAsString());
// trigger the webscript temp folder cleaner job
CronTrigger webscriptsTempFileCleanerJobTrigger = (CronTrigger) getServer().getApplicationContext().getBean("webscripts.tempFileCleanerTrigger");
Scheduler scheduler = (Scheduler) getServer().getApplicationContext().getBean("schedulerFactory");
scheduler.triggerJob(webscriptsTempFileCleanerJobTrigger.getJobKey());
// check that we still can upload file larger than 4 mb, i.e. ensure that cleaner has not deleted temp folder
response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
assertEquals(SUCCESS, response.getContentAsString());
}
Aggregations