Search in sources :

Example 71 with JobDetail

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);
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Example 72 with JobDetail

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);
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Example 73 with JobDetail

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;
}
Also used : JobDetail(org.quartz.JobDetail)

Example 74 with JobDetail

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;
}
Also used : JobDetail(org.quartz.JobDetail) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException)

Example 75 with JobDetail

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));
                }
            }
        }
    }
}
Also used : TimeRangeCalendar(org.openhab.io.gcal.internal.util.TimeRangeCalendar) JobDetail(org.quartz.JobDetail) LongRange(org.apache.commons.lang.math.LongRange) HashMap(java.util.HashMap) Event(com.google.api.services.calendar.model.Event)

Aggregations

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4