use of org.motechproject.scheduler.contract.JobId in project motech by motech.
the class MotechSchedulerServiceImpl method scheduleRepeatingPeriodJob.
private void scheduleRepeatingPeriodJob(RepeatingPeriodSchedulableJob job, boolean update) {
logObjectIfNotNull(job);
validateRepeatingPeriodSchedulableJob(job);
MotechEvent motechEvent = job.getMotechEvent();
JobId jobId = new RepeatingPeriodJobId(motechEvent);
JobDetail jobDetail = newJob(MotechScheduledJob.class).withIdentity(jobKey(jobId.value(), JOB_GROUP_NAME)).build();
putMotechEventDataToJobDataMap(jobDetail.getJobDataMap(), motechEvent);
jobDetail.getJobDataMap().put(EVENT_METADATA, createMetadataForMisfireSchedulableJob(job, motechEvent));
ScheduleBuilder scheduleBuilder = PeriodIntervalScheduleBuilder.periodIntervalSchedule().withRepeatPeriod(job.getRepeatPeriod()).withMisfireHandlingInstructionFireAndProceed();
Trigger trigger = buildJobDetail(job, DateUtil.toDate(job.getStartDate()), DateUtil.toDate(job.getEndDate()), jobId, jobDetail, scheduleBuilder);
scheduleJob(jobDetail, trigger, update);
}
use of org.motechproject.scheduler.contract.JobId 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