Search in sources :

Example 1 with MotechSchedulerException

use of org.motechproject.scheduler.exception.MotechSchedulerException 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 MotechSchedulerException

use of org.motechproject.scheduler.exception.MotechSchedulerException 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 MotechSchedulerException

use of org.motechproject.scheduler.exception.MotechSchedulerException in project motech by motech.

the class MotechSchedulerServiceImpl method unscheduleJob.

private void unscheduleJob(String jobId) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(jobId);
    }
    try {
        assertArgumentNotNull("ScheduledJobID", jobId);
        scheduler.unscheduleJob(triggerKey(jobId, JOB_GROUP_NAME));
    } catch (SchedulerException e) {
        throw new MotechSchedulerException(String.format("Can not unschedule the job: %s %s", jobId, e.getMessage()), e);
    }
}
Also used : MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException) SchedulerException(org.quartz.SchedulerException) MotechSchedulerException(org.motechproject.scheduler.exception.MotechSchedulerException)

Example 4 with MotechSchedulerException

use of org.motechproject.scheduler.exception.MotechSchedulerException 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 5 with MotechSchedulerException

use of org.motechproject.scheduler.exception.MotechSchedulerException 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)

Aggregations

MotechSchedulerException (org.motechproject.scheduler.exception.MotechSchedulerException)19 SchedulerException (org.quartz.SchedulerException)11 CronJobId (org.motechproject.scheduler.contract.CronJobId)9 JobId (org.motechproject.scheduler.contract.JobId)9 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)9 RepeatingPeriodJobId (org.motechproject.scheduler.contract.RepeatingPeriodJobId)9 RunOnceJobId (org.motechproject.scheduler.contract.RunOnceJobId)9 CronTrigger (org.quartz.CronTrigger)6 SimpleTrigger (org.quartz.SimpleTrigger)5 Trigger (org.quartz.Trigger)5 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 OperableTrigger (org.quartz.spi.OperableTrigger)5 DateTime (org.joda.time.DateTime)4 JobDetail (org.quartz.JobDetail)4 MotechEvent (org.motechproject.event.MotechEvent)3 CronScheduleBuilder (org.quartz.CronScheduleBuilder)3 JobKey (org.quartz.JobKey)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)2