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"));
}
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));
}
}
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));
}
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);
}
}
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);
}
}
Aggregations