use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class MotechSchedulerServiceImpl method deleteJob.
@Override
public void deleteJob(JobBasicInfo info) {
try {
JobKey key = new JobKey(info.getName(), info.getGroup());
validateJob(key);
scheduler.deleteJob(key);
} catch (MotechSchedulerException | SchedulerException e) {
throw new MotechSchedulerException(String.format("Can not delete the job:\n %s\n%s\n%s", info.getName(), info.getGroup(), e.getMessage()), e);
}
}
use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class MotechSchedulerServiceImpl method scheduleJob.
private void scheduleJob(JobDetail jobDetail, Trigger trigger, boolean update) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Scheduling job:" + jobDetail);
}
try {
Set<Trigger> triggerSet = new HashSet<>();
triggerSet.add(trigger);
scheduler.scheduleJob(jobDetail, triggerSet, update);
} catch (SchedulerException e) {
throw new MotechSchedulerException(String.format("Can not schedule the job:\n %s\n%s\n%s", jobDetail.toString(), trigger.toString(), e.getMessage()), "scheduler.error.schedulerError", Arrays.asList(e.getMessage()), e);
}
}
use of org.motechproject.scheduler.exception.MotechSchedulerException 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);
}
}
use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.
the class SchedulableJobBuilder method buildJob.
/**
* Builds a job based on the given key, data map and trigger.
*
* @param key the job key
* @param dataMap the job data map
* @param trigger the job trigger
* @return the created job
* @throws SchedulerException when there were problems while building job
*/
public static SchedulableJob buildJob(JobKey key, JobDataMap dataMap, Trigger trigger) throws SchedulerException {
SchedulableJob job;
Map<String, Object> params = dataMap.getWrappedMap();
Map<String, Object> metadata = (Map<String, Object>) params.get(EVENT_METADATA);
params.remove(EVENT_METADATA);
params.putAll(metadata);
JobDataMap map = new JobDataMap(params);
switch(getJobType(key, map)) {
case CRON:
job = buildCronSchedulableJob(trigger, map);
break;
case REPEATING:
job = buildRepeatingSchedulableJob(trigger, map);
break;
case REPEATING_PERIOD:
job = buildRepeatingPeriodSchedulableJob(trigger, map);
break;
case DAY_OF_WEEK:
job = buildDayOfWeekSchedulableJob(trigger, map);
break;
case RUN_ONCE:
job = buildRunOnceSchedulableJob();
break;
default:
throw new MotechSchedulerException(String.format("Unknown job type: \n %s\n %s", key.getName(), key.getGroup()));
}
job.setMotechEvent(new MotechEvent(dataMap.getString(EVENT_TYPE_KEY_NAME), map.getWrappedMap()));
job.setUiDefined(map.getBoolean(UI_DEFINED));
job.setStartDate(new DateTime(trigger.getStartTime()));
return job;
}
Aggregations