Search in sources :

Example 1 with RunOnceJobId

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());
}
Also used : RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId)

Example 2 with RunOnceJobId

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);
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) SimpleScheduleBuilder(org.quartz.SimpleScheduleBuilder) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId)

Example 3 with RunOnceJobId

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);
}
Also used : MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId)

Aggregations

CronJobId (org.motechproject.scheduler.contract.CronJobId)3 JobId (org.motechproject.scheduler.contract.JobId)3 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)3 RepeatingPeriodJobId (org.motechproject.scheduler.contract.RepeatingPeriodJobId)3 RunOnceJobId (org.motechproject.scheduler.contract.RunOnceJobId)3 HashMap (java.util.HashMap)1 MotechEvent (org.motechproject.event.MotechEvent)1 MotechSchedulerException (org.motechproject.scheduler.exception.MotechSchedulerException)1 CronTrigger (org.quartz.CronTrigger)1 JobDetail (org.quartz.JobDetail)1 SimpleScheduleBuilder (org.quartz.SimpleScheduleBuilder)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)1 OperableTrigger (org.quartz.spi.OperableTrigger)1