Search in sources :

Example 1 with Trigger

use of org.quartz.Trigger in project elastic-job by dangdangdotcom.

the class JobRunningStatisticJobTest method assertBuildTrigger.

@Test
public void assertBuildTrigger() throws SchedulerException {
    Trigger trigger = jobRunningStatisticJob.buildTrigger();
    assertThat(trigger.getKey().getName(), is(JobRunningStatisticJob.class.getSimpleName() + "Trigger"));
}
Also used : Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 2 with Trigger

use of org.quartz.Trigger in project elastic-job by dangdangdotcom.

the class TaskResultStatisticJobTest method assertBuildTrigger.

@Test
public void assertBuildTrigger() throws SchedulerException {
    for (StatisticInterval each : StatisticInterval.values()) {
        taskResultStatisticJob.setStatisticInterval(each);
        Trigger trigger = taskResultStatisticJob.buildTrigger();
        assertThat(trigger.getKey().getName(), is(TaskResultStatisticJob.class.getSimpleName() + "Trigger" + "_" + each));
    }
}
Also used : Trigger(org.quartz.Trigger) StatisticInterval(com.dangdang.ddframe.job.statistics.StatisticInterval) Test(org.junit.Test)

Example 3 with Trigger

use of org.quartz.Trigger in project elastic-job by dangdangdotcom.

the class JobScheduleControllerTest method assertGetNextFireTime.

@SuppressWarnings("unchecked")
@Test
public void assertGetNextFireTime() throws NoSuchFieldException, SchedulerException {
    ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
    ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail);
    JobKey jobKey = new JobKey("test_job");
    Trigger trigger1 = mock(Trigger.class);
    Trigger trigger2 = mock(Trigger.class);
    Trigger trigger3 = mock(Trigger.class);
    Trigger trigger4 = mock(Trigger.class);
    @SuppressWarnings("rawtypes") List triggers = Arrays.asList(trigger1, trigger2, trigger3, trigger4);
    when(trigger1.getNextFireTime()).thenReturn(null);
    when(trigger2.getNextFireTime()).thenReturn(new Date(1L));
    when(trigger3.getNextFireTime()).thenReturn(new Date(100L));
    when(trigger4.getNextFireTime()).thenReturn(new Date(0L));
    when(jobDetail.getKey()).thenReturn(jobKey);
    when(scheduler.getTriggersOfJob(jobKey)).thenReturn(triggers);
    assertThat(jobScheduleController.getNextFireTime().getTime(), is(0L));
}
Also used : JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Trigger

use of org.quartz.Trigger in project jmxtrans by jmxtrans.

the class JmxTransformer method scheduleJob.

private void scheduleJob(Server server) throws ParseException, SchedulerException {
    String name = server.getHost() + ":" + server.getPort() + "-" + System.currentTimeMillis() + "-" + RandomStringUtils.randomNumeric(10);
    JobDetail jd = new JobDetail(name, "ServerJob", ServerJob.class);
    JobDataMap map = new JobDataMap();
    map.put(Server.class.getName(), server);
    jd.setJobDataMap(map);
    Trigger trigger;
    if ((server.getCronExpression() != null) && CronExpression.isValidExpression(server.getCronExpression())) {
        trigger = new CronTrigger();
        ((CronTrigger) trigger).setCronExpression(server.getCronExpression());
        trigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
        trigger.setStartTime(computeSpreadStartDate(configuration.getRunPeriod()));
    } else {
        int runPeriod = configuration.getRunPeriod();
        if (server.getRunPeriodSeconds() != null)
            runPeriod = server.getRunPeriodSeconds();
        Trigger minuteTrigger = TriggerUtils.makeSecondlyTrigger(runPeriod);
        minuteTrigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
        minuteTrigger.setStartTime(computeSpreadStartDate(runPeriod));
        trigger = minuteTrigger;
    // TODO replace Quartz with a ScheduledExecutorService
    }
    serverScheduler.scheduleJob(jd, trigger);
    if (log.isDebugEnabled()) {
        log.debug("Scheduled job: " + jd.getName() + " for server: " + server);
    }
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server)

Example 5 with Trigger

use of org.quartz.Trigger in project pinot by linkedin.

the class AlertJobScheduler method run.

public void run() {
    try {
        // read all alert configs
        LOG.info("Reading all alert configs..");
        List<EmailConfigurationDTO> alertConfigs = emailConfigurationDAO.findAll();
        // get active jobs
        List<String> scheduledJobs = getScheduledJobs();
        LOG.info("Scheduled jobs {}", scheduledJobs);
        for (EmailConfigurationDTO alertConfig : alertConfigs) {
            Long id = alertConfig.getId();
            String jobKey = getJobKey(id);
            boolean isActive = alertConfig.isActive();
            boolean isScheduled = scheduledJobs.contains(jobKey);
            // schedule them with quartz, as function is newly created, or newly activated
            if (isActive && !isScheduled) {
                LOG.info("Found active but not scheduled {}", id);
                startJob(alertConfig, jobKey);
            } else // remove them from quartz, as function is newly deactivated
            if (!isActive && isScheduled) {
                LOG.info("Found inactive but scheduled {}", id);
                stopJob(jobKey);
            } else // but check for cron updates
            if (isActive && isScheduled) {
                String cronInDatabase = alertConfig.getCron();
                List<Trigger> triggers = (List<Trigger>) quartzScheduler.getTriggersOfJob(JobKey.jobKey(jobKey));
                CronTrigger cronTrigger = (CronTrigger) triggers.get(0);
                String cronInSchedule = cronTrigger.getCronExpression();
                // cron expression has been updated, restart this job
                if (!cronInDatabase.equals(cronInSchedule)) {
                    LOG.info("Cron expression for config {} with jobKey {} has been changed from {}  to {}. " + "Restarting schedule", id, jobKey, cronInSchedule, cronInDatabase);
                    stopJob(jobKey);
                    startJob(alertConfig, jobKey);
                }
            }
        // for all jobs with not isActive, and not isScheduled, no change required
        }
        // stop the schedule, as function has been deleted
        for (String scheduledJobKey : scheduledJobs) {
            Long configId = getIdFromJobKey(scheduledJobKey);
            EmailConfigurationDTO alertConfigSpec = emailConfigurationDAO.findById(configId);
            if (alertConfigSpec == null) {
                LOG.info("Found scheduled, but not in database {}", configId);
                stopJob(scheduledJobKey);
            }
        }
    } catch (SchedulerException e) {
        LOG.error("Exception in reading active jobs", e);
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList) List(java.util.List) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Aggregations

Trigger (org.quartz.Trigger)98 JobDetail (org.quartz.JobDetail)47 SchedulerException (org.quartz.SchedulerException)37 CronTrigger (org.quartz.CronTrigger)28 Test (org.junit.Test)23 JobDataMap (org.quartz.JobDataMap)21 Scheduler (org.quartz.Scheduler)21 TriggerKey (org.quartz.TriggerKey)20 SimpleTrigger (org.quartz.SimpleTrigger)19 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)18 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4