Search in sources :

Example 46 with JobDetail

use of org.quartz.JobDetail in project engine by craftercms.

the class SchedulingUtils method createScriptJob.

public static JobDetail createScriptJob(SiteContext siteContext, String jobName, String scriptUrl, ServletContext servletContext) {
    JobDataMap dataMap = new JobDataMap();
    dataMap.put(SITE_CONTEXT_DATA_KEY, siteContext);
    dataMap.put(SCRIPT_URL_DATA_KEY, scriptUrl);
    dataMap.put(SERVLET_CONTEXT_DATA_KEY, servletContext);
    JobDetail job = newJob(ScriptJob.class).withIdentity(jobName).setJobData(dataMap).build();
    return job;
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) ScriptJob(org.craftercms.engine.scripting.impl.ScriptJob)

Example 47 with JobDetail

use of org.quartz.JobDetail in project ddf by codice.

the class ScheduledCommandTask method newTask.

@Override
public void newTask() {
    LOGGER.trace("Creating new Task.");
    long identifier = System.currentTimeMillis();
    this.jobKey = new JobKey("job" + identifier, jobClass.getSimpleName());
    this.triggerKey = new TriggerKey("trigger" + identifier, jobClass.getSimpleName());
    JobDetail jobDetail = createJob();
    Trigger trigger = createTrigger();
    if (trigger == null) {
        return;
    }
    try {
        scheduler.scheduleJob(jobDetail, trigger);
    } catch (SchedulerException e) {
        LOGGER.info("Error with scheduling of task.", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Example 48 with JobDetail

use of org.quartz.JobDetail in project cdap by caskdata.

the class TimeScheduler method schedule.

public synchronized void schedule(ProgramId program, SchedulableProgramType programType, Iterable<Schedule> schedules, Map<String, String> properties) throws SchedulerException {
    checkInitialized();
    try {
        validateSchedules(program, programType, schedules);
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(e);
    }
    JobDetail job = addJob(program, programType);
    for (Schedule schedule : schedules) {
        TimeSchedule timeSchedule = (TimeSchedule) schedule;
        String scheduleName = timeSchedule.getName();
        String cronEntry = timeSchedule.getCronEntry();
        scheduleJob(program, programType, scheduleName, cronEntry, job, properties);
    }
}
Also used : JobDetail(org.quartz.JobDetail) Schedule(co.cask.cdap.api.schedule.Schedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule)

Example 49 with JobDetail

use of org.quartz.JobDetail in project cdap by caskdata.

the class DatasetBasedTimeScheduleStore method readJob.

private JobDetail readJob(Table table, JobKey key) {
    byte[][] col = new byte[1][];
    col[0] = Bytes.toBytes(key.toString());
    Row row = table.get(JOB_KEY, col);
    byte[] bytes = null;
    if (!row.isEmpty()) {
        bytes = row.get(col[0]);
    }
    if (bytes != null) {
        return (JobDetail) SerializationUtils.deserialize(bytes);
    } else {
        return null;
    }
}
Also used : JobDetail(org.quartz.JobDetail) Row(co.cask.cdap.api.dataset.table.Row)

Example 50 with JobDetail

use of org.quartz.JobDetail in project cdap by caskdata.

the class DatasetBasedTimeScheduleStore method readSchedulesFromPersistentStore.

// Get schedule information from persistent store
private void readSchedulesFromPersistentStore() throws Exception {
    final List<JobDetail> jobs = Lists.newArrayList();
    final List<TriggerStatusV2> triggers = Lists.newArrayList();
    factory.createExecutor(ImmutableList.of((TransactionAware) table)).execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Row result = table.get(JOB_KEY);
            if (!result.isEmpty()) {
                for (byte[] bytes : result.getColumns().values()) {
                    JobDetail jobDetail = (JobDetail) SerializationUtils.deserialize(bytes);
                    // If the job detail doesn't contain version id, add one.
                    jobDetail = addDefaultAppVersionIfNeeded(jobDetail);
                    LOG.debug("Schedule: Job with key {} found", jobDetail.getKey());
                    jobs.add(jobDetail);
                }
            } else {
                LOG.debug("Schedule: No Jobs found in Job store");
            }
            result = table.get(TRIGGER_KEY);
            if (!result.isEmpty()) {
                for (byte[] bytes : result.getColumns().values()) {
                    TriggerStatusV2 trigger = (TriggerStatusV2) SerializationUtils.deserialize(bytes);
                    addDefaultAppVersionIfNeeded(trigger);
                    if (trigger.state.equals(Trigger.TriggerState.NORMAL) || trigger.state.equals(Trigger.TriggerState.PAUSED)) {
                        triggers.add(trigger);
                        LOG.debug("Schedule: trigger with key {} added", trigger.trigger.getKey());
                    } else {
                        LOG.debug("Schedule: trigger with key {} and state {} skipped", trigger.trigger.getKey(), trigger.state);
                    }
                }
            } else {
                LOG.debug("Schedule: No triggers found in job store");
            }
        }
    });
    for (JobDetail job : jobs) {
        super.storeJob(job, true);
    }
    for (TriggerStatusV2 trigger : triggers) {
        super.storeTrigger(trigger.trigger, true);
        // because the scheduler is actually not started at this point.
        if (trigger.state == Trigger.TriggerState.PAUSED) {
            super.pauseTrigger(trigger.trigger.getKey());
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) TransactionExecutor(org.apache.tephra.TransactionExecutor) Row(co.cask.cdap.api.dataset.table.Row) TransactionFailureException(org.apache.tephra.TransactionFailureException) JobPersistenceException(org.quartz.JobPersistenceException) TransactionConflictException(org.apache.tephra.TransactionConflictException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException) IOException(java.io.IOException)

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