Search in sources :

Example 1 with JobId

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

the class MotechSchedulerServiceImpl method safeScheduleJob.

@Override
public void safeScheduleJob(CronSchedulableJob cronSchedulableJob) {
    logObjectIfNotNull(cronSchedulableJob);
    assertCronJob(cronSchedulableJob);
    JobId jobId = new CronJobId(cronSchedulableJob.getMotechEvent());
    try {
        unscheduleJob(jobId.value());
    } catch (MotechSchedulerException e) {
        LOGGER.error("Error while unscheduling job with id {}", jobId.value(), e);
    }
    scheduleJob(cronSchedulableJob);
}
Also used : CronJobId(org.motechproject.scheduler.contract.CronJobId) 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 JobId

use of org.motechproject.scheduler.contract.JobId 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 3 with JobId

use of org.motechproject.scheduler.contract.JobId 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 4 with JobId

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

the class MotechSchedulerServiceImpl method getScheduledJobTimingsWithPrefix.

/*
     * Loads all triggers and then loops over them to find the applicable trigger using string comparison. This
     * will work regardless of the jobId being cron or repeating.
     */
@Override
public List<DateTime> getScheduledJobTimingsWithPrefix(String subject, String externalJobIdPrefix, DateTime startDate, DateTime endDate) {
    JobId jobId = new CronJobId(subject, externalJobIdPrefix);
    List<Date> messageTimings = new ArrayList<>();
    try {
        List<TriggerKey> triggerKeys = new ArrayList<TriggerKey>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
        for (TriggerKey triggerKey : triggerKeys) {
            if (StringUtils.isNotEmpty(externalJobIdPrefix) && triggerKey.getName().contains(jobId.value())) {
                Trigger trigger = scheduler.getTrigger(triggerKey);
                messageTimings.addAll(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 externalJobIdPrefix for dates : %s %s %s %s %s", subject, externalJobIdPrefix, startDate.toString(), endDate.toString(), e.getMessage()), e);
    }
    return DateUtil.datesToDateTimes(messageTimings);
}
Also used : TriggerKey(org.quartz.TriggerKey) 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) ArrayList(java.util.ArrayList) 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) Date(java.util.Date)

Example 5 with JobId

use of org.motechproject.scheduler.contract.JobId 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)

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