use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class MotechSchedulerServiceImpl method safeScheduleJob.
@Override
public void safeScheduleJob(CronSchedulableJob cronSchedulableJob) {
logObjectIfNotNull(cronSchedulableJob);
assertCronJob(cronSchedulableJob);
JobId jobId = new CronJobId(cronSchedulableJob.getMotechEvent());
try {
unscheduleJob(jobId.value());
} catch (MotechSchedulerException e) {
LOGGER.error("Error while unscheduling job with id {}", jobId.value(), e);
}
scheduleJob(cronSchedulableJob);
}
use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class MotechSchedulerServiceImpl method safeScheduleRepeatingPeriodJob.
@Override
public void safeScheduleRepeatingPeriodJob(RepeatingPeriodSchedulableJob repeatingPeriodSchedulableJob) {
logObjectIfNotNull(repeatingPeriodSchedulableJob);
assertArgumentNotNull(repeatingPeriodSchedulableJob);
JobId jobId = new RepeatingJobId(repeatingPeriodSchedulableJob.getMotechEvent());
try {
unscheduleJob(jobId);
} catch (MotechSchedulerException e) {
LOGGER.error("Unable to unschedule repeating job with id {}", jobId.value(), e);
}
scheduleRepeatingPeriodJob(repeatingPeriodSchedulableJob);
}
use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class MotechSchedulerServiceImpl method unscheduleJob.
private void unscheduleJob(String jobId) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(jobId);
}
try {
assertArgumentNotNull("ScheduledJobID", jobId);
scheduler.unscheduleJob(triggerKey(jobId, JOB_GROUP_NAME));
} catch (SchedulerException e) {
throw new MotechSchedulerException(String.format("Can not unschedule the job: %s %s", jobId, e.getMessage()), e);
}
}
use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class MotechSchedulerServiceImpl method safeScheduleRepeatingJob.
@Override
public void safeScheduleRepeatingJob(RepeatingSchedulableJob repeatingSchedulableJob) {
logObjectIfNotNull(repeatingSchedulableJob);
assertArgumentNotNull(repeatingSchedulableJob);
JobId jobId = new RepeatingJobId(repeatingSchedulableJob.getMotechEvent());
try {
unscheduleJob(jobId);
} catch (MotechSchedulerException e) {
LOGGER.error("Unable to unschedule repeating job with ID {}", jobId.value(), e);
}
scheduleRepeatingJob(repeatingSchedulableJob);
}
use of org.motechproject.scheduler.exception.MotechSchedulerException 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);
}
Aggregations