Search in sources :

Example 16 with JobId

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

the class MotechSchedulerServiceImpl method scheduleRepeatingPeriodJob.

private void scheduleRepeatingPeriodJob(RepeatingPeriodSchedulableJob job, boolean update) {
    logObjectIfNotNull(job);
    validateRepeatingPeriodSchedulableJob(job);
    MotechEvent motechEvent = job.getMotechEvent();
    JobId jobId = new RepeatingPeriodJobId(motechEvent);
    JobDetail jobDetail = newJob(MotechScheduledJob.class).withIdentity(jobKey(jobId.value(), JOB_GROUP_NAME)).build();
    putMotechEventDataToJobDataMap(jobDetail.getJobDataMap(), motechEvent);
    jobDetail.getJobDataMap().put(EVENT_METADATA, createMetadataForMisfireSchedulableJob(job, motechEvent));
    ScheduleBuilder scheduleBuilder = PeriodIntervalScheduleBuilder.periodIntervalSchedule().withRepeatPeriod(job.getRepeatPeriod()).withMisfireHandlingInstructionFireAndProceed();
    Trigger trigger = buildJobDetail(job, DateUtil.toDate(job.getStartDate()), DateUtil.toDate(job.getEndDate()), jobId, jobDetail, scheduleBuilder);
    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) PeriodIntervalScheduleBuilder(org.motechproject.scheduler.trigger.PeriodIntervalScheduleBuilder) ScheduleBuilder(org.quartz.ScheduleBuilder) SimpleScheduleBuilder(org.quartz.SimpleScheduleBuilder) CalendarIntervalScheduleBuilder(org.quartz.CalendarIntervalScheduleBuilder) CronScheduleBuilder(org.quartz.CronScheduleBuilder) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) MotechEvent(org.motechproject.event.MotechEvent) 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 17 with JobId

use of org.motechproject.scheduler.contract.JobId 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);
    }
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) SchedulerException(org.quartz.SchedulerException) CronJobId(org.motechproject.scheduler.contract.CronJobId) BaseCalendar(org.quartz.impl.calendar.BaseCalendar) 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)

Aggregations

JobId (org.motechproject.scheduler.contract.JobId)17 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)17 CronJobId (org.motechproject.scheduler.contract.CronJobId)16 RepeatingPeriodJobId (org.motechproject.scheduler.contract.RepeatingPeriodJobId)13 RunOnceJobId (org.motechproject.scheduler.contract.RunOnceJobId)13 MotechSchedulerException (org.motechproject.scheduler.exception.MotechSchedulerException)9 CronTrigger (org.quartz.CronTrigger)7 MotechEvent (org.motechproject.event.MotechEvent)6 SimpleTrigger (org.quartz.SimpleTrigger)6 Trigger (org.quartz.Trigger)6 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)6 OperableTrigger (org.quartz.spi.OperableTrigger)6 JobDetail (org.quartz.JobDetail)5 SchedulerException (org.quartz.SchedulerException)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)4 Test (org.junit.Test)3 SimpleScheduleBuilder (org.quartz.SimpleScheduleBuilder)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 DateTime (org.joda.time.DateTime)2