use of org.quartz.JobDetail in project pinot by linkedin.
the class AlertJobScheduler method runAdHoc.
public void runAdHoc(Long id, DateTime windowStartTime, DateTime windowEndTime) {
EmailConfigurationDTO alertConfig = emailConfigurationDAO.findById(id);
if (alertConfig == null) {
throw new IllegalArgumentException("No alert config with id " + id);
}
String triggerKey = String.format("alert_adhoc_trigger_%d", id);
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).startNow().build();
String jobKey = "adhoc_" + getJobKey(id);
JobDetail job = JobBuilder.newJob(AlertJobRunner.class).withIdentity(jobKey).build();
AlertJobContext alertJobContext = new AlertJobContext();
alertJobContext.setJobDAO(anomalyJobDAO);
alertJobContext.setTaskDAO(anomalyTaskDAO);
alertJobContext.setEmailConfigurationDAO(emailConfigurationDAO);
alertJobContext.setAlertConfigId(id);
alertJobContext.setJobName(jobKey);
job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_CONTEXT, alertJobContext);
job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_START_TIME, windowStartTime);
job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_END_TIME, windowEndTime);
try {
quartzScheduler.scheduleJob(job, trigger);
} catch (SchedulerException e) {
LOG.error("Exception while scheduling job", e);
}
LOG.info("Started {}: {}", jobKey, alertConfig);
}
use of org.quartz.JobDetail in project elastic-job by dangdangdotcom.
the class DaemonTaskScheduler method init.
/**
* 初始化作业.
*/
public void init() {
JobDetail jobDetail = JobBuilder.newJob(DaemonJob.class).withIdentity(jobRootConfig.getTypeConfig().getCoreConfig().getJobName()).build();
jobDetail.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJob);
jobDetail.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade);
jobDetail.getJobDataMap().put(EXECUTOR_DRIVER_DATA_MAP_KEY, executorDriver);
jobDetail.getJobDataMap().put(TASK_ID_DATA_MAP_KEY, taskId);
try {
scheduleJob(initializeScheduler(), jobDetail, taskId.getValue(), jobRootConfig.getTypeConfig().getCoreConfig().getCron());
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
}
use of org.quartz.JobDetail in project elastic-job by dangdangdotcom.
the class TransientProducerScheduler method buildJobDetail.
private JobDetail buildJobDetail(final JobKey jobKey) {
JobDetail result = JobBuilder.newJob(ProducerJob.class).withIdentity(jobKey).build();
result.getJobDataMap().put("repository", repository);
result.getJobDataMap().put("readyService", readyService);
return result;
}
use of org.quartz.JobDetail in project spring-framework by spring-projects.
the class SchedulerAccessor method addTriggerToScheduler.
/**
* Add the given trigger to the Scheduler, if it doesn't already exist.
* Overwrites the trigger in any case if "overwriteExistingJobs" is set.
* @param trigger the trigger to add
* @return {@code true} if the trigger was actually added,
* {@code false} if it already existed before
* @see #setOverwriteExistingJobs
*/
private boolean addTriggerToScheduler(Trigger trigger) throws SchedulerException {
boolean triggerExists = (getScheduler().getTrigger(trigger.getKey()) != null);
if (triggerExists && !this.overwriteExistingJobs) {
return false;
}
// Check if the Trigger is aware of an associated JobDetail.
JobDetail jobDetail = (JobDetail) trigger.getJobDataMap().remove("jobDetail");
if (triggerExists) {
if (jobDetail != null && !this.jobDetails.contains(jobDetail) && addJobToScheduler(jobDetail)) {
this.jobDetails.add(jobDetail);
}
getScheduler().rescheduleJob(trigger.getKey(), trigger);
} else {
try {
if (jobDetail != null && !this.jobDetails.contains(jobDetail) && (this.overwriteExistingJobs || getScheduler().getJobDetail(jobDetail.getKey()) == null)) {
getScheduler().scheduleJob(jobDetail, trigger);
this.jobDetails.add(jobDetail);
} else {
getScheduler().scheduleJob(trigger);
}
} catch (ObjectAlreadyExistsException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Unexpectedly found existing trigger, assumably due to cluster race condition: " + ex.getMessage() + " - can safely be ignored");
}
if (this.overwriteExistingJobs) {
getScheduler().rescheduleJob(trigger.getKey(), trigger);
}
}
}
return true;
}
use of org.quartz.JobDetail in project openhab1-addons by openhab.
the class GCalEventDownloader method processEntries.
/**
* <p>
* Iterates through <code>entries</code>, extracts the event content and
* creates quartz calendars, jobs and corresponding triggers for each event.
* </p>
* <p>
* The following steps are done at event processing:
* <ul>
* <li>find events with empty content</li>
* <li>create a {@link TimeRangeCalendar} for each event (unique by title) and add a TimeRange for each {@link When}
* </li>
* <li>add each {@link TimeRangeCalendar} to the {@link Scheduler}</li>
* <li>find events with content</li>
* <li>add a Job with the corresponding Triggers for each event</li>
* </ul>
*
* @param entries the GCalendar events to create quart jobs for.
* @throws SchedulerException if there is an internal Scheduler error.
*/
private void processEntries(List<Event> entries) throws SchedulerException {
Map<String, TimeRangeCalendar> calendarCache = new HashMap<String, TimeRangeCalendar>();
// the scheduler
for (Event event : entries) {
String eventContent = event.getDescription();
String eventTitle = event.getSummary();
if (StringUtils.isBlank(eventContent)) {
logger.debug("found event '{}' with no content, add this event to the excluded TimeRangesCalendar - this event could be referenced by the modifiedBy clause", eventTitle);
if (!calendarCache.containsKey(eventTitle)) {
calendarCache.put(eventTitle, new TimeRangeCalendar());
}
TimeRangeCalendar timeRangeCalendar = calendarCache.get(eventTitle);
timeRangeCalendar.addTimeRange(new LongRange(event.getStart().getDateTime().getValue(), event.getEnd().getDateTime().getValue()));
}
}
// the calendars has to be added first, to schedule Triggers successfully
for (Entry<String, TimeRangeCalendar> entry : calendarCache.entrySet()) {
scheduler.addCalendar(entry.getKey(), entry.getValue(), true, true);
}
// now we process all events with content
for (Event event : entries) {
String eventContent = event.getDescription();
String eventTitle = event.getSummary();
if (StringUtils.isNotBlank(eventContent)) {
CalendarEventContent cec = parseEventContent(eventContent, (eventTitle != null) && eventTitle.startsWith("[PresenceSimulation]"));
String modifiedByEvent = null;
if (calendarCache.containsKey(cec.modifiedByEvent)) {
modifiedByEvent = cec.modifiedByEvent;
}
JobDetail startJob = createJob(cec.startCommands, event, true);
boolean triggersCreated = createTriggerAndSchedule(startJob, event, modifiedByEvent, true);
if (triggersCreated) {
logger.debug("created new startJob '{}' with details '{}'", eventTitle, createJobInfo(event, startJob));
}
// do only create end-jobs if there are end-commands ...
if (StringUtils.isNotBlank(cec.endCommands)) {
JobDetail endJob = createJob(cec.endCommands, event, false);
triggersCreated = createTriggerAndSchedule(endJob, event, modifiedByEvent, false);
if (triggersCreated) {
logger.debug("created new endJob '{}' with details '{}'", eventTitle, createJobInfo(event, endJob));
}
}
}
}
}
Aggregations