Search in sources :

Example 1 with RepeatingJobId

use of org.motechproject.scheduler.contract.RepeatingJobId 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);
}
Also used : RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) 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)

Example 2 with RepeatingJobId

use of org.motechproject.scheduler.contract.RepeatingJobId 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);
}
Also used : RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) 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)

Example 3 with RepeatingJobId

use of org.motechproject.scheduler.contract.RepeatingJobId in project motech by motech.

the class JobIdTest method initializeUsingMotechEvent.

@Test
public void initializeUsingMotechEvent() {
    MotechEvent motechEvent = new MotechEvent(SUBJECT_VALUE);
    motechEvent.getParameters().put(MotechSchedulerService.JOB_ID_KEY, JOB_ID_VALUE);
    JobId jobId = new CronJobId(motechEvent);
    assertEquals(String.format("%s-%s", SUBJECT_VALUE, JOB_ID_VALUE), jobId.value());
    jobId = new RepeatingJobId(motechEvent);
    assertEquals(String.format("%s-%s%s", SUBJECT_VALUE, JOB_ID_VALUE, RepeatingJobId.SUFFIX_REPEATJOBID), jobId.value());
}
Also used : CronJobId(org.motechproject.scheduler.contract.CronJobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) MotechEvent(org.motechproject.event.MotechEvent) JobId(org.motechproject.scheduler.contract.JobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) Test(org.junit.Test)

Example 4 with RepeatingJobId

use of org.motechproject.scheduler.contract.RepeatingJobId in project motech by motech.

the class MotechSchedulerListener method handleUnscheduleRepeatingJobEvent.

/**
 * Handles the motech event unscheduling an existing repeating job.
 *
 * @param event the event to be handled
 */
@MotechListener(subjects = { UNSCHEDULE_REPEATING_JOB })
public void handleUnscheduleRepeatingJobEvent(MotechEvent event) {
    Map<String, Object> metadata = event.getMetadata();
    String jobSubject = (String) metadata.get(JOB_SUBJECT);
    MotechEvent jobEvent = new MotechEvent(jobSubject, null);
    JobId jobId = new RepeatingJobId(jobEvent);
    schedulerService.unscheduleJob(jobId);
}
Also used : RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) MotechEvent(org.motechproject.event.MotechEvent) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) MotechListener(org.motechproject.event.listener.annotations.MotechListener)

Example 5 with RepeatingJobId

use of org.motechproject.scheduler.contract.RepeatingJobId in project motech by motech.

the class JobIdTest method repeatingId.

@Test
public void repeatingId() {
    JobId jobId = new RepeatingJobId(SUBJECT_VALUE, JOB_ID_VALUE);
    assertEquals(String.format("%s-%s%s", SUBJECT_VALUE, JOB_ID_VALUE, RepeatingJobId.SUFFIX_REPEATJOBID), jobId.value());
}
Also used : RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) JobId(org.motechproject.scheduler.contract.JobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) Test(org.junit.Test)

Aggregations

JobId (org.motechproject.scheduler.contract.JobId)7 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)7 CronJobId (org.motechproject.scheduler.contract.CronJobId)6 RepeatingPeriodJobId (org.motechproject.scheduler.contract.RepeatingPeriodJobId)4 RunOnceJobId (org.motechproject.scheduler.contract.RunOnceJobId)4 MotechEvent (org.motechproject.event.MotechEvent)3 MotechSchedulerException (org.motechproject.scheduler.exception.MotechSchedulerException)3 Test (org.junit.Test)2 DateTime (org.joda.time.DateTime)1 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)1 MotechListener (org.motechproject.event.listener.annotations.MotechListener)1 PeriodIntervalScheduleBuilder (org.motechproject.scheduler.trigger.PeriodIntervalScheduleBuilder)1 CalendarIntervalScheduleBuilder (org.quartz.CalendarIntervalScheduleBuilder)1 CronScheduleBuilder (org.quartz.CronScheduleBuilder)1 CronTrigger (org.quartz.CronTrigger)1 JobDetail (org.quartz.JobDetail)1 ScheduleBuilder (org.quartz.ScheduleBuilder)1 SchedulerException (org.quartz.SchedulerException)1 SimpleScheduleBuilder (org.quartz.SimpleScheduleBuilder)1 SimpleTrigger (org.quartz.SimpleTrigger)1