use of org.quartz.spi.OperableTrigger in project Saturn by vipshop.
the class JobScheduler method getNextFireTimePausePeriodEffected.
/**
* 获取下次作业触发时间.可能被暂停时间段所影响。
*
* @return 下次作业触发时间
*/
public Date getNextFireTimePausePeriodEffected() {
SaturnScheduler saturnScheduler = job.getScheduler();
if (saturnScheduler == null) {
return null;
}
Trigger trigger = saturnScheduler.getTrigger();
if (trigger == null) {
return null;
}
((OperableTrigger) trigger).updateAfterMisfire(null);
Date nextFireTime = trigger.getNextFireTime();
while (nextFireTime != null && configService.isInPausePeriod(nextFireTime)) {
nextFireTime = trigger.getFireTimeAfter(nextFireTime);
}
if (null == nextFireTime) {
return null;
}
return nextFireTime;
}
use of org.quartz.spi.OperableTrigger in project motech by motech.
the class MotechSchedulerServiceImpl method buildJobDetail.
private Trigger buildJobDetail(SchedulableJob schedulableJob, Date jobStartTime, Date jobEndTime, JobId jobId, JobDetail jobDetail, ScheduleBuilder scheduleBuilder) {
Trigger trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(scheduleBuilder).startAt(jobStartTime).endAt(jobEndTime).build();
DateTime now = now();
if (schedulableJob.isIgnorePastFiresAtStart() && newDateTime(jobStartTime).isBefore(now)) {
List<Date> pastTriggers = TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, null, jobStartTime, now.toDate());
if (pastTriggers.size() > 0) {
if (scheduleBuilder instanceof SimpleScheduleBuilder && ((RepeatingSchedulableJob) schedulableJob).getRepeatCount() != null) {
((SimpleScheduleBuilder) scheduleBuilder).withRepeatCount(((RepeatingSchedulableJob) schedulableJob).getRepeatCount() - pastTriggers.size());
}
Date newStartTime = getFirstTriggerInFuture(trigger, now);
trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(scheduleBuilder).startAt(newStartTime).endAt(jobEndTime).build();
}
}
return trigger;
}
use of org.quartz.spi.OperableTrigger in project motech by motech.
the class MotechSchedulerServiceImpl method getScheduledJobTimingsWithPrefix.
/*
* Loads all triggers and then loops over them to find the applicable trigger using string comparison. This
* will work regardless of the jobId being cron or repeating.
*/
@Override
public List<DateTime> getScheduledJobTimingsWithPrefix(String subject, String externalJobIdPrefix, DateTime startDate, DateTime endDate) {
JobId jobId = new CronJobId(subject, externalJobIdPrefix);
List<Date> messageTimings = new ArrayList<>();
try {
List<TriggerKey> triggerKeys = new ArrayList<TriggerKey>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
for (TriggerKey triggerKey : triggerKeys) {
if (StringUtils.isNotEmpty(externalJobIdPrefix) && triggerKey.getName().contains(jobId.value())) {
Trigger trigger = scheduler.getTrigger(triggerKey);
messageTimings.addAll(TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate)));
}
}
} catch (SchedulerException e) {
throw new MotechSchedulerException(String.format("Can not get scheduled job timings given subject and externalJobIdPrefix for dates : %s %s %s %s %s", subject, externalJobIdPrefix, startDate.toString(), endDate.toString(), e.getMessage()), e);
}
return DateUtil.datesToDateTimes(messageTimings);
}
use of org.quartz.spi.OperableTrigger in project candlepin by candlepin.
the class HighlanderFactoryTest method testNewJob.
@Test
public void testNewJob() throws SchedulerException, ParseException {
assertNotNull(hf);
try {
hf.newJob(null, null);
fail("should've died with npe");
} catch (NullPointerException npe) {
// Expected
}
String crontab = "0 0 12 * * ?";
JobDetail jd = newJob(TestJob.class).withIdentity("testjob", "group").build();
Trigger trigger = newTrigger().withIdentity("testjob", "group").withSchedule(cronSchedule(crontab)).build();
TriggerFiredBundle tfb = new TriggerFiredBundle(jd, (OperableTrigger) trigger, null, false, null, null, null, null);
Job j = hf.newJob(tfb, null);
assertNotNull(j);
}
use of org.quartz.spi.OperableTrigger in project motech by motech.
the class MotechSchedulerServiceImpl method getScheduledJobTimings.
/*
* Assumes that the externalJobId is non-repeating in nature. Thus the fetch is for jobId.value() and not
* jobId.repeatingId()
* Uses quartz API to fetch the exact triggers. Fast
*/
@Override
public List<DateTime> getScheduledJobTimings(String subject, String externalJobId, DateTime startDate, DateTime endDate) {
JobId jobId = new CronJobId(subject, externalJobId);
Trigger trigger;
try {
trigger = scheduler.getTrigger(triggerKey(jobId.value(), JOB_GROUP_NAME));
return DateUtil.datesToDateTimes(TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, new BaseCalendar(), DateUtil.toDate(startDate), DateUtil.toDate(endDate)));
} catch (SchedulerException e) {
throw new MotechSchedulerException(String.format("Can not get scheduled job timings given subject and externalJobId for dates : %s %s %s %s %s", subject, externalJobId, startDate.toString(), endDate.toString(), e.getMessage()), e);
}
}
Aggregations