use of org.motechproject.scheduler.contract.RepeatingJobId in project motech by motech.
the class MotechSchedulerServiceImpl method unscheduleRepeatingJob.
@Override
public void unscheduleRepeatingJob(String subject, String externalId) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("unscheduling repeating job: " + LOG_SUBJECT_EXTERNAL_ID, subject, externalId));
}
JobId jobId = new RepeatingJobId(subject, externalId);
logObjectIfNotNull(jobId);
unscheduleJob(jobId.value());
}
use of org.motechproject.scheduler.contract.RepeatingJobId in project motech by motech.
the class MotechSchedulerServiceImpl method scheduleRepeatingJob.
private void scheduleRepeatingJob(RepeatingSchedulableJob job, boolean update) {
logObjectIfNotNull(job);
validateRepeatingSchedulableJob(job);
MotechEvent motechEvent = job.getMotechEvent();
DateTime jobStartTime = job.getStartDate();
DateTime jobEndTime = job.getEndDate();
Integer repeatIntervalInSeconds = job.getRepeatIntervalInSeconds();
Integer jobRepeatCount = job.getRepeatCount();
if (null == jobRepeatCount) {
jobRepeatCount = MAX_REPEAT_COUNT;
}
JobId jobId = new RepeatingJobId(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));
try {
if (scheduler.getTrigger(triggerKey(jobId.value(), JOB_GROUP_NAME)) != null) {
unscheduleJob(jobId);
}
} catch (SchedulerException e) {
throw new MotechSchedulerException(format("Schedule or reschedule the job: %s.\n%s", jobId, e.getMessage()), "scheduler.error.cantRescheduleJob", Arrays.asList(jobId.value(), e.getMessage()), e);
}
ScheduleBuilder scheduleBuilder;
if (!job.isUseOriginalFireTimeAfterMisfire()) {
SimpleScheduleBuilder simpleSchedule = simpleSchedule().withIntervalInSeconds(repeatIntervalInSeconds).withRepeatCount(jobRepeatCount);
simpleSchedule = setMisfirePolicyForSimpleTrigger(simpleSchedule, schedulerSettings.getProperty("scheduler.repeating.trigger.misfire.policy"));
scheduleBuilder = simpleSchedule;
} else {
if (job.getRepeatCount() != null) {
final double half = 0.5;
jobEndTime = new DateTime((long) (job.getStartDate().getMillis() + repeatIntervalInSeconds * MILLISECOND * (job.getRepeatCount() + half)));
}
scheduleBuilder = CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInSeconds(repeatIntervalInSeconds).withMisfireHandlingInstructionFireAndProceed();
}
Trigger trigger = buildJobDetail(job, DateUtil.toDate(jobStartTime), DateUtil.toDate(jobEndTime), jobId, jobDetail, scheduleBuilder);
scheduleJob(jobDetail, trigger, update);
}
Aggregations