Search in sources :

Example 81 with TriggerKey

use of org.quartz.TriggerKey in project kylo by Teradata.

the class QuartzScheduler method scheduleWithFixedDelay.

public void scheduleWithFixedDelay(JobIdentifier jobIdentifier, Object task, String runMethod, Date startTime, long startDelay) throws JobSchedulerException {
    try {
        JobDetail jobDetail = getJobDetail(jobIdentifier, task, runMethod);
        Date triggerStartTime = startTime;
        if (startDelay > 0L || startTime == null) {
            triggerStartTime = new Date(System.currentTimeMillis() + startDelay);
        }
        Trigger trigger = newTrigger().withIdentity(new TriggerKey(jobIdentifier.getName(), jobIdentifier.getGroup())).forJob(jobDetail).startAt(triggerStartTime).build();
        getScheduler().scheduleJob(jobDetail, trigger);
        triggerListeners(JobSchedulerEvent.scheduledJobEvent(jobIdentifier));
    } 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) Date(java.util.Date) ParseException(java.text.ParseException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException)

Example 82 with TriggerKey

use of org.quartz.TriggerKey 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)

Example 83 with TriggerKey

use of org.quartz.TriggerKey in project kylo by Teradata.

the class QuartzSchedulerTest method staticHelperTest.

@Test
public void staticHelperTest() throws Exception {
    JobIdentifier identifier = QuartzScheduler.jobIdentifierForJobKey(new JobKey("job-name", "group"));
    JobKey jobKey = QuartzScheduler.jobKeyForJobIdentifier(identifier);
    assertEquals(jobKey.getName(), identifier.getName());
    TriggerKey triggerKey = new TriggerKey("trigger-key-name", "trigger-key-name");
    TriggerIdentifier triggerIdentifier = QuartzScheduler.triggerIdentifierForTriggerKey(triggerKey);
    triggerKey = QuartzScheduler.triggerKeyForTriggerIdentifier(triggerIdentifier);
    assertEquals(triggerKey.getName(), triggerIdentifier.getName());
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) DefaultTriggerIdentifier(com.thinkbiganalytics.scheduler.model.DefaultTriggerIdentifier) Test(org.junit.Test)

Example 84 with TriggerKey

use of org.quartz.TriggerKey in project BRFS by zhangnianli.

the class QuartzBaseSchedulers method pauseTask.

@Override
public boolean pauseTask(T task) throws Exception {
    TriggerKey triggerKey = TriggerKey.triggerKey(task.getTaskName(), task.getTaskGroupName());
    JobKey jobKey = new JobKey(task.getTaskName(), task.getTaskGroupName());
    Scheduler scheduler = this.ssf.getScheduler(this.instanceName);
    if (!scheduler.isShutdown()) {
        // 1.停止触发器
        scheduler.pauseTrigger(triggerKey);
        // 2.停止任务
        scheduler.pauseJob(jobKey);
    }
    return true;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) Scheduler(org.quartz.Scheduler)

Example 85 with TriggerKey

use of org.quartz.TriggerKey in project BRFS by zhangnianli.

the class QuartzBaseSchedulers method resumeTask.

@Override
public boolean resumeTask(T task) throws Exception {
    TriggerKey triggerKey = TriggerKey.triggerKey(task.getTaskName(), task.getTaskGroupName());
    JobKey jobKey = new JobKey(task.getTaskName(), task.getTaskGroupName());
    Scheduler scheduler = this.ssf.getScheduler(this.instanceName);
    if (!scheduler.isShutdown()) {
        Set<String> pauseGroup = scheduler.getPausedTriggerGroups();
        if (pauseGroup == null || (pauseGroup != null && !pauseGroup.contains(task.getTaskGroupName()))) {
            return false;
        }
        scheduler.resumeTrigger(triggerKey);
        scheduler.resumeJob(jobKey);
    }
    return true;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) Scheduler(org.quartz.Scheduler)

Aggregations

TriggerKey (org.quartz.TriggerKey)112 Trigger (org.quartz.Trigger)49 JobKey (org.quartz.JobKey)30 SchedulerException (org.quartz.SchedulerException)30 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Test (org.junit.Test)18 Scheduler (org.quartz.Scheduler)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4