use of org.motechproject.scheduler.contract.RunOnceJobId in project motech by motech.
the class MotechSchedulerServiceImpl method unscheduleRunOnceJob.
@Override
public void unscheduleRunOnceJob(String subject, String externalId) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("unscheduling run once job: " + LOG_SUBJECT_EXTERNAL_ID, subject, externalId));
}
JobId jobId = new RunOnceJobId(subject, externalId);
logObjectIfNotNull(jobId);
unscheduleJob(jobId.value());
}
use of org.motechproject.scheduler.contract.RunOnceJobId in project motech by motech.
the class MotechSchedulerServiceImpl method scheduleRunOnceJob.
private void scheduleRunOnceJob(RunOnceSchedulableJob job, boolean update) {
logObjectIfNotNull(job);
validateRunOnceSchedulableJob(job);
MotechEvent motechEvent = job.getMotechEvent();
JobId jobId = new RunOnceJobId(motechEvent);
JobDetail jobDetail = newJob(MotechScheduledJob.class).withIdentity(jobId.value(), JOB_GROUP_NAME).build();
putMotechEventDataToJobDataMap(jobDetail.getJobDataMap(), motechEvent);
Map<String, Object> metadata = new HashMap<>();
metadata.put(UI_DEFINED, job.isUiDefined());
metadata.putAll(motechEvent.getMetadata());
jobDetail.getJobDataMap().put(EVENT_METADATA, metadata);
SimpleScheduleBuilder simpleSchedule = simpleSchedule().withRepeatCount(0).withIntervalInSeconds(0).withMisfireHandlingInstructionFireNow();
Trigger trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(simpleSchedule).startAt(DateUtil.toDate(job.getStartDate())).build();
scheduleJob(jobDetail, trigger, update);
}
use of org.motechproject.scheduler.contract.RunOnceJobId in project motech by motech.
the class MotechSchedulerServiceImpl method safeScheduleRunOnceJob.
@Override
public void safeScheduleRunOnceJob(RunOnceSchedulableJob schedulableJob) {
logObjectIfNotNull(schedulableJob);
assertArgumentNotNull("RunOnceSchedulableJob", schedulableJob);
JobId jobId = new RunOnceJobId(schedulableJob.getMotechEvent());
try {
unscheduleJob(jobId);
} catch (MotechSchedulerException e) {
LOGGER.error("Unable to unschedule run once job with ID {}", jobId.value(), e);
}
scheduleRunOnceJob(schedulableJob);
}
Aggregations