use of org.quartz.JobDetail in project zeppelin by apache.
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.JobDetail in project elastic-job by dangdangdotcom.
the class JobScheduler method createJobDetail.
private JobDetail createJobDetail(final String jobClass) {
JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(jobName).build();
result.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade);
Optional<ElasticJob> elasticJobInstance = createElasticJobInstance();
if (elasticJobInstance.isPresent()) {
result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJobInstance.get());
} else if (!jobClass.equals(ScriptJob.class.getCanonicalName())) {
try {
result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, Class.forName(jobClass).newInstance());
} catch (final ReflectiveOperationException ex) {
throw new JobConfigurationException("Elastic-Job: Job class '%s' can not initialize.", jobClass);
}
}
return result;
}
use of org.quartz.JobDetail in project elastic-job by dangdangdotcom.
the class StatisticsScheduler method register.
/**
* 注册统计作业.
*
* @param statisticJob 统计作业
*/
void register(final StatisticJob statisticJob) {
try {
JobDetail jobDetail = statisticJob.buildJobDetail();
Map<String, Object> dataMap = statisticJob.getDataMap();
for (String each : dataMap.keySet()) {
jobDetail.getJobDataMap().put(each, dataMap.get(each));
}
scheduler.scheduleJob(jobDetail, statisticJob.buildTrigger());
} catch (final SchedulerException ex) {
throw new JobStatisticException(ex);
}
}
use of org.quartz.JobDetail in project elastic-job by dangdangdotcom.
the class TaskResultStatisticJob method buildJobDetail.
@Override
public JobDetail buildJobDetail() {
JobDetail result = JobBuilder.newJob(this.getClass()).withIdentity(getJobName() + "_" + statisticInterval).build();
result.getJobDataMap().put("statisticUnit", statisticInterval);
return result;
}
use of org.quartz.JobDetail in project jmxtrans by jmxtrans.
the class JmxTransformer method scheduleJob.
private void scheduleJob(Server server) throws ParseException, SchedulerException {
String name = server.getHost() + ":" + server.getPort() + "-" + System.currentTimeMillis() + "-" + RandomStringUtils.randomNumeric(10);
JobDetail jd = new JobDetail(name, "ServerJob", ServerJob.class);
JobDataMap map = new JobDataMap();
map.put(Server.class.getName(), server);
jd.setJobDataMap(map);
Trigger trigger;
if ((server.getCronExpression() != null) && CronExpression.isValidExpression(server.getCronExpression())) {
trigger = new CronTrigger();
((CronTrigger) trigger).setCronExpression(server.getCronExpression());
trigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
trigger.setStartTime(computeSpreadStartDate(configuration.getRunPeriod()));
} else {
int runPeriod = configuration.getRunPeriod();
if (server.getRunPeriodSeconds() != null)
runPeriod = server.getRunPeriodSeconds();
Trigger minuteTrigger = TriggerUtils.makeSecondlyTrigger(runPeriod);
minuteTrigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
minuteTrigger.setStartTime(computeSpreadStartDate(runPeriod));
trigger = minuteTrigger;
// TODO replace Quartz with a ScheduledExecutorService
}
serverScheduler.scheduleJob(jd, trigger);
if (log.isDebugEnabled()) {
log.debug("Scheduled job: " + jd.getName() + " for server: " + server);
}
}
Aggregations