Search in sources :

Example 1 with CalendarIntervalTrigger

use of org.quartz.CalendarIntervalTrigger in project motech by motech.

the class MotechSchedulerDatabaseServiceImpl method getJobInfo.

private String getJobInfo(Trigger trigger, String jobType) throws SchedulerException {
    if (jobType.equals(JobBasicInfo.JOBTYPE_REPEATING)) {
        Integer timesTriggered = 0;
        String repeatMaxCount = "-";
        if (trigger instanceof CalendarIntervalTrigger) {
            CalendarIntervalTrigger calendarIntervalTrigger = (CalendarIntervalTrigger) trigger;
            timesTriggered = calendarIntervalTrigger.getTimesTriggered();
        } else if (trigger instanceof SimpleTrigger) {
            SimpleTrigger simpleTrigger = (SimpleTrigger) trigger;
            timesTriggered = simpleTrigger.getTimesTriggered();
        }
        if (trigger.getEndTime() != null) {
            repeatMaxCount = Integer.toString(TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, null, trigger.getStartTime(), trigger.getEndTime()).size() + timesTriggered);
        }
        return String.format("%d/%s", timesTriggered, repeatMaxCount);
    } else if (jobType.equals(JobBasicInfo.JOBTYPE_CRON)) {
        CronScheduleBuilder cronScheduleBuilder = (CronScheduleBuilder) trigger.getScheduleBuilder();
        CronTrigger cronTrigger = (CronTrigger) cronScheduleBuilder.build();
        return cronTrigger.getCronExpression();
    } else {
        return "-";
    }
}
Also used : CronScheduleBuilder(org.quartz.CronScheduleBuilder) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger) CalendarIntervalTrigger(org.quartz.CalendarIntervalTrigger)

Example 2 with CalendarIntervalTrigger

use of org.quartz.CalendarIntervalTrigger in project motech by motech.

the class SchedulableJobBuilder method buildRepeatingSchedulableJob.

private static SchedulableJob buildRepeatingSchedulableJob(Trigger trigger, JobDataMap dataMap) {
    RepeatingSchedulableJob job = new RepeatingSchedulableJob();
    long interval;
    if (trigger instanceof CalendarIntervalTrigger) {
        CalendarIntervalTrigger calendarTrigger = (CalendarIntervalTrigger) trigger;
        interval = calendarTrigger.getRepeatInterval();
    } else {
        SimpleTrigger simpleTrigger = (SimpleTrigger) trigger;
        job.setRepeatCount(simpleTrigger.getRepeatCount());
        interval = simpleTrigger.getRepeatInterval() / SECOND;
    }
    job.setEndDate(getEndDate(trigger));
    job.setRepeatIntervalInSeconds((int) interval);
    job.setIgnorePastFiresAtStart(dataMap.getBoolean(IGNORE_PAST_FIRES_AT_START));
    job.setUseOriginalFireTimeAfterMisfire(dataMap.getBoolean(USE_ORIGINAL_FIRE_TIME_AFTER_MISFIRE));
    return job;
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) SimpleTrigger(org.quartz.SimpleTrigger) CalendarIntervalTrigger(org.quartz.CalendarIntervalTrigger)

Aggregations

CalendarIntervalTrigger (org.quartz.CalendarIntervalTrigger)2 SimpleTrigger (org.quartz.SimpleTrigger)2 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)1 CronScheduleBuilder (org.quartz.CronScheduleBuilder)1 CronTrigger (org.quartz.CronTrigger)1