Search in sources :

Example 1 with TriggerBuilder.newTrigger

use of org.quartz.TriggerBuilder.newTrigger in project kylo by Teradata.

the class QuartzScheduler method scheduleWithCronExpressionInTimeZone.

public void scheduleWithCronExpressionInTimeZone(JobIdentifier jobIdentifier, Object task, String runMethod, String cronExpression, TimeZone timeZone) throws JobSchedulerException {
    try {
        JobDetail jobDetail = getJobDetail(jobIdentifier, task, runMethod);
        if (timeZone == null) {
            timeZone = TimeZone.getDefault();
        }
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(new TriggerKey("trigger_" + jobIdentifier.getUniqueName(), jobIdentifier.getGroup())).forJob(jobDetail).withSchedule(CronScheduleBuilder.cronSchedule(cronExpression).inTimeZone(timeZone).withMisfireHandlingInstructionFireAndProceed()).build();
        scheduleJob(jobDetail, trigger);
    } catch (Exception e) {
        throw new JobSchedulerException();
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) ParseException(java.text.ParseException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException)

Example 2 with TriggerBuilder.newTrigger

use of org.quartz.TriggerBuilder.newTrigger in project kylo by Teradata.

the class QuartzScheduler method scheduleAtFixedRateWithDelay.

public void scheduleAtFixedRateWithDelay(JobIdentifier jobIdentifier, Object task, String runMethod, Date startTime, long period, long startDelay) throws JobSchedulerException {
    JobDetail jobDetail = null;
    try {
        jobDetail = getJobDetail(jobIdentifier, task, runMethod);
        Date triggerStartTime = startTime;
        if (startDelay > 0L || startTime == null) {
            triggerStartTime = new Date(System.currentTimeMillis() + startDelay);
        }
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(new TriggerKey(jobIdentifier.getName(), jobIdentifier.getGroup())).forJob(jobDetail).startAt(triggerStartTime).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(period).repeatForever()).build();
        getScheduler().scheduleJob(jobDetail, trigger);
        triggerListeners(JobSchedulerEvent.scheduledJobEvent(jobIdentifier));
    } catch (NoSuchMethodException | ClassNotFoundException | SchedulerException e) {
        throw new JobSchedulerException("Error calling scheduleAtFixedRateWithDelay", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException) Date(java.util.Date)

Aggregations

CronTrigger (org.quartz.CronTrigger)2 JobDetail (org.quartz.JobDetail)2 SchedulerException (org.quartz.SchedulerException)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Trigger (org.quartz.Trigger)2 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)2 TriggerKey (org.quartz.TriggerKey)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1