use of org.quartz.SchedulerException 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.SchedulerException in project pinot by linkedin.
the class AlertJobScheduler method scheduleJob.
private void scheduleJob(JobContext jobContext, EmailConfigurationDTO alertConfig) {
LOG.info("Starting {}", jobContext.getJobName());
String triggerKey = String.format("alert_scheduler_trigger_%d", alertConfig.getId());
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(CronScheduleBuilder.cronSchedule(alertConfig.getCron())).build();
String jobKey = jobContext.getJobName();
JobDetail job = JobBuilder.newJob(AlertJobRunner.class).withIdentity(jobKey).build();
job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_CONTEXT, jobContext);
try {
quartzScheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
LOG.error("Exception while scheduling alert job", e);
}
LOG.info("Started {}: {}", jobKey, alertConfig);
}
use of org.quartz.SchedulerException in project pinot by linkedin.
the class AlertJobScheduler method run.
public void run() {
try {
// read all alert configs
LOG.info("Reading all alert configs..");
List<EmailConfigurationDTO> alertConfigs = emailConfigurationDAO.findAll();
// get active jobs
List<String> scheduledJobs = getScheduledJobs();
LOG.info("Scheduled jobs {}", scheduledJobs);
for (EmailConfigurationDTO alertConfig : alertConfigs) {
Long id = alertConfig.getId();
String jobKey = getJobKey(id);
boolean isActive = alertConfig.isActive();
boolean isScheduled = scheduledJobs.contains(jobKey);
// schedule them with quartz, as function is newly created, or newly activated
if (isActive && !isScheduled) {
LOG.info("Found active but not scheduled {}", id);
startJob(alertConfig, jobKey);
} else // remove them from quartz, as function is newly deactivated
if (!isActive && isScheduled) {
LOG.info("Found inactive but scheduled {}", id);
stopJob(jobKey);
} else // but check for cron updates
if (isActive && isScheduled) {
String cronInDatabase = alertConfig.getCron();
List<Trigger> triggers = (List<Trigger>) quartzScheduler.getTriggersOfJob(JobKey.jobKey(jobKey));
CronTrigger cronTrigger = (CronTrigger) triggers.get(0);
String cronInSchedule = cronTrigger.getCronExpression();
// cron expression has been updated, restart this job
if (!cronInDatabase.equals(cronInSchedule)) {
LOG.info("Cron expression for config {} with jobKey {} has been changed from {} to {}. " + "Restarting schedule", id, jobKey, cronInSchedule, cronInDatabase);
stopJob(jobKey);
startJob(alertConfig, jobKey);
}
}
// for all jobs with not isActive, and not isScheduled, no change required
}
// stop the schedule, as function has been deleted
for (String scheduledJobKey : scheduledJobs) {
Long configId = getIdFromJobKey(scheduledJobKey);
EmailConfigurationDTO alertConfigSpec = emailConfigurationDAO.findById(configId);
if (alertConfigSpec == null) {
LOG.info("Found scheduled, but not in database {}", configId);
stopJob(scheduledJobKey);
}
}
} catch (SchedulerException e) {
LOG.error("Exception in reading active jobs", e);
}
}
use of org.quartz.SchedulerException in project pinot by linkedin.
the class AlertJobSchedulerV2 method scheduleJob.
private void scheduleJob(JobContext jobContext, AlertConfigDTO alertConfig) {
LOG.info("Starting {}", jobContext.getJobName());
String triggerKey = String.format("alert_scheduler_trigger_%d", alertConfig.getId());
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(CronScheduleBuilder.cronSchedule(alertConfig.getCronExpression())).build();
String jobKey = jobContext.getJobName();
JobDetail job = JobBuilder.newJob(AlertJobRunnerV2.class).withIdentity(jobKey).build();
job.getJobDataMap().put(AlertJobRunnerV2.ALERT_JOB_CONTEXT_V2, jobContext);
try {
quartzScheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
LOG.error("Exception while scheduling alert job", e);
}
LOG.info("Started {}: {}", jobKey, alertConfig);
}
use of org.quartz.SchedulerException in project pinot by linkedin.
the class AlertJobSchedulerV2 method run.
public void run() {
try {
// read all alert configs
LOG.info("Reading all alert configs..");
List<AlertConfigDTO> alertConfigs = alertConfigDAO.findAll();
// get active jobs
List<String> scheduledJobs = getScheduledJobs();
LOG.info("Scheduled jobs {}", scheduledJobs);
for (AlertConfigDTO alertConfig : alertConfigs) {
Long id = alertConfig.getId();
String jobKey = getJobKey(id);
boolean isActive = alertConfig.isActive();
boolean isScheduled = scheduledJobs.contains(jobKey);
if (isActive) {
if (isScheduled) {
String cronInDatabase = alertConfig.getCronExpression();
List<Trigger> triggers = (List<Trigger>) quartzScheduler.getTriggersOfJob(JobKey.jobKey(jobKey));
CronTrigger cronTrigger = (CronTrigger) triggers.get(0);
String cronInSchedule = cronTrigger.getCronExpression();
// cron expression has been updated, restart this job
if (!cronInDatabase.equals(cronInSchedule)) {
LOG.info("Cron expression for config {} with jobKey {} has been changed from {} to {}. " + "Restarting schedule", id, jobKey, cronInSchedule, cronInDatabase);
stopJob(jobKey);
startJob(alertConfig, jobKey);
}
} else {
LOG.info("Found active but not scheduled {}", id);
startJob(alertConfig, jobKey);
}
} else {
if (isScheduled) {
LOG.info("Found inactive but scheduled {}", id);
stopJob(jobKey);
}
// for all jobs with not isActive, and not isScheduled, no change required
}
}
// stop the schedule, as function has been deleted
for (String scheduledJobKey : scheduledJobs) {
Long configId = getIdFromJobKey(scheduledJobKey);
AlertConfigDTO alertConfigSpec = alertConfigDAO.findById(configId);
if (alertConfigSpec == null) {
LOG.info("Found scheduled, but not in database {}", configId);
stopJob(scheduledJobKey);
}
}
} catch (SchedulerException e) {
LOG.error("Exception in reading active jobs", e);
}
}
Aggregations