@Override protected TriggerPropertyBundle getTriggerPropertyBundle(SimplePropertiesTriggerProperties props) { TimeZone tz = null; // if we use null, that's ok as system default tz will be used String tzId = props.getString2(); if(tzId != null && tzId.trim().length() != 0) // there could be null entries from previously released versions tz = TimeZone.getTimeZone(tzId); ScheduleBuilder<?> sb = CalendarIntervalScheduleBuilder.calendarIntervalSchedule() .withInterval(props.getInt1(), IntervalUnit.valueOf(props.getString1())) .inTimeZone(tz) .preserveHourOfDayAcrossDaylightSavings(props.isBoolean1()) .skipDayIfHourDoesNotExist(props.isBoolean2()); int timesTriggered = props.getInt2(); String[] statePropertyNames = { "timesTriggered" }; Object[] statePropertyValues = { timesTriggered }; return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues); }
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<CronTrigger> getScheduleBuilder() { CronScheduleBuilder cb = CronScheduleBuilder.cronSchedule(getCronExpression()) .inTimeZone(getTimeZone()); switch(getMisfireInstruction()) { case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing(); break; case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed(); break; } return cb; }
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<DailyTimeIntervalTrigger> getScheduleBuilder() { DailyTimeIntervalScheduleBuilder cb = DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule() .withInterval(getRepeatInterval(), getRepeatIntervalUnit()) .onDaysOfTheWeek(getDaysOfWeek()).startingDailyAt(getStartTimeOfDay()).endingDailyAt(getEndTimeOfDay()); switch(getMisfireInstruction()) { case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing(); break; case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed(); break; } return cb; }
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<CalendarIntervalTrigger> getScheduleBuilder() { CalendarIntervalScheduleBuilder cb = CalendarIntervalScheduleBuilder.calendarIntervalSchedule() .withInterval(getRepeatInterval(), getRepeatIntervalUnit()); switch(getMisfireInstruction()) { case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing(); break; case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed(); break; } return cb; }
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<SimpleTrigger> getScheduleBuilder() { SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule() .withIntervalInMilliseconds(getRepeatInterval()) .withRepeatCount(getRepeatCount()); switch(getMisfireInstruction()) { case MISFIRE_INSTRUCTION_FIRE_NOW : sb.withMisfireHandlingInstructionFireNow(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT : sb.withMisfireHandlingInstructionNextWithExistingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT : sb.withMisfireHandlingInstructionNextWithRemainingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithExistingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithRemainingCount(); break; } return sb; }
private ScheduleBuilder<? extends Trigger> parseAtExpr(String atExpr) { Matcher matcher = AT_EXPR_PATTERN.matcher(atExpr); if (!matcher.find()) { throwException(atExpr); } if (matcher.group(1).equals("??")) { String cronExpression = "0 " + matcher.group(2) + " * * * ?"; return parseCron(cronExpression); } val formatter = DateTimeFormat.forPattern("HH:mm"); val dateTime = formatter.parseDateTime(matcher.group().trim()); int hourOfDay = dateTime.getHourOfDay(); int minuteOfHour = dateTime.getMinuteOfHour(); return dailyAtHourAndMinute(hourOfDay, minuteOfHour); }
private ScheduleBuilder<? extends Trigger> parseEveryExpr(String everyExpr) { Matcher matcher = EVERY_EXPR_PATTERN.matcher(everyExpr); if (!matcher.find()) return throwException(everyExpr); int num = Integer.parseInt(matcher.group(1)); if (num <= 0) throwException(everyExpr); char unit = matcher.group(2).charAt(0); TimeUnit timeUnit = parseTimeUnit(unit); return simpleSchedule() .withIntervalInSeconds((int) timeUnit.toSeconds(num)) .repeatForever(); }
@Test public void testAcquireNextTriggerAfterMissFire_doesNotTrigger_ifNextScheduleTimeOutOfRange() throws Exception { long baseFireTime = newDate().build().getTime(); JobDetail job = JobBuilder.newJob(NoOpJob.class).build(); jobStore.storeJob(job, true); ScheduleBuilder scheduleBuilder = simpleSchedule().withIntervalInSeconds(3).repeatForever() .withMisfireHandlingInstructionNextWithExistingCount(); OperableTrigger t1 = buildAndComputeTrigger("trigger1", "triggerGroup1", job, baseFireTime + 500, null, scheduleBuilder); jobStore.storeTrigger(t1, false); assertAcquiredAndRelease(baseFireTime, 1); Thread.sleep(5000); // missed one execution (3 seconds tick is more than 1 seconds ago), next execution (at 6 seconds tick) is not yet picked up assertAcquiredAndRelease(newDate().build().getTime() + 250, 0); // try acquire on larger interval (containing 6 sec tick) assertAcquiredAndRelease(newDate().build().getTime() + 1550, 1); }
protected OperableTrigger buildTrigger(String triggerName, String triggerGroup, JobDetail job, Long startAt, Long endAt, ScheduleBuilder scheduleBuilder) { ScheduleBuilder schedule = scheduleBuilder!=null?scheduleBuilder : SimpleScheduleBuilder.simpleSchedule(); return (OperableTrigger) TriggerBuilder .newTrigger() .withIdentity(triggerName, triggerGroup) .forJob(job) .startAt(startAt != null ? new Date(startAt) : null) .endAt(endAt != null ? new Date(endAt) : null) .withSchedule(schedule) .build(); }
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); }
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<PeriodIntervalTrigger> getScheduleBuilder() { PeriodIntervalScheduleBuilder sb = PeriodIntervalScheduleBuilder.periodIntervalSchedule() .withRepeatPeriod(repeatPeriod) .withMisfireHandlingInstructionDoNothing(); switch (getMisfireInstruction()) { case MISFIRE_INSTRUCTION_DO_NOTHING : sb.withMisfireHandlingInstructionDoNothing(); break; case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : sb.withMisfireHandlingInstructionFireAndProceed(); break; } return sb; }
@Override public void scheduleRepeatingJob(long interval) { Date jobStartTime = DateUtil.nowUTC().toDate(); if (interval == 0) { throw new IllegalArgumentException("Invalid RepeatingSchedulableJob. The job repeat interval can not be 0"); } JobDetail jobDetail = newJob(MdsScheduledJob.class) .withIdentity(jobKey(EMPTY_TRASH_JOB, JOB_GROUP_NAME)) .build(); ScheduleBuilder scheduleBuilder = simpleSchedule() .withIntervalInMilliseconds(interval) .withRepeatCount(MAX_REPEAT_COUNT); Trigger trigger = buildJobDetail(jobStartTime, jobDetail, scheduleBuilder); scheduleJob(jobDetail, trigger); }
private static Scheduled schedule( Runnable runnable, ScheduleBuilder<?> scheduleBuilder ) { try { String identity = identity( runnable ); JobDetail job = newJob( RunnableJob.class ) .withIdentity( identity + "/job" ) .storeDurably() .build(); Trigger trigger = newTrigger() .withIdentity( identity + "/trigger" ) .withSchedule( scheduleBuilder ) .build(); jobFactory.register( job, runnable ); scheduler.scheduleJob( job, trigger ); log.trace( "scheduling job {} with trigger {}", job, trigger ); return new QuartzScheduled( job ); } catch( org.quartz.SchedulerException e ) { throw new SchedulerException( e ); } }
private ScheduleBuilder<? extends Trigger> createScheduleBuilder() { if (StringUtils.startsWithIgnoreCase(schedulerExpr, "Every")) { return parseEveryExpr(schedulerExpr.substring("Every".length())); } else if (StringUtils.startsWithIgnoreCase(schedulerExpr, "At")) { return parseAtExpr(schedulerExpr.substring("At".length())); } else { return parseCron(schedulerExpr); } }
@Override @JsonIgnore public ScheduleBuilder getScheduleBuilder() { return new ScheduleBuilder<SimpleTrigger>() { @Override protected MutableTrigger build() { return SimpleScheduleBuilder.simpleSchedule() .withRepeatCount(repeatCount) .withIntervalInMilliseconds(repeatInterval) .withMisfireHandlingInstructionNextWithRemainingCount() .build(); } }; }
protected OperableTrigger buildAndComputeTrigger(String triggerName, String triggerGroup, JobDetail job, Long startAt, Long endAt, ScheduleBuilder scheduleBuilder) { OperableTrigger trigger = buildTrigger(triggerName, triggerGroup, job, startAt, endAt, scheduleBuilder); trigger.computeFirstFireTime(null); return trigger; }
private Trigger buildJobDetail(SchedulableJob schedulableJob, Date jobStartTime, Date jobEndTime, JobId jobId, JobDetail jobDetail, ScheduleBuilder scheduleBuilder) { Trigger trigger = newTrigger() .withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)) .forJob(jobDetail) .withSchedule(scheduleBuilder) .startAt(jobStartTime) .endAt(jobEndTime) .build(); DateTime now = now(); if (schedulableJob.isIgnorePastFiresAtStart() && newDateTime(jobStartTime).isBefore(now)) { List<Date> pastTriggers = TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger, null, jobStartTime, now.toDate()); if (pastTriggers.size() > 0) { if (scheduleBuilder instanceof SimpleScheduleBuilder && ((RepeatingSchedulableJob) schedulableJob).getRepeatCount() != null) { ((SimpleScheduleBuilder) scheduleBuilder) .withRepeatCount(((RepeatingSchedulableJob) schedulableJob).getRepeatCount() - pastTriggers.size()); } Date newStartTime = getFirstTriggerInFuture(trigger, now); trigger = newTrigger() .withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)) .forJob(jobDetail) .withSchedule(scheduleBuilder) .startAt(newStartTime) .endAt(jobEndTime) .build(); } } return trigger; }
@Override protected TriggerPropertyBundle getTriggerPropertyBundle(SimplePropertiesTriggerProperties properties) { Period repeatPeriod = Period.parse(properties.getString1()); ScheduleBuilder<?> sb = PeriodIntervalScheduleBuilder.periodIntervalSchedule() .withRepeatPeriod(repeatPeriod); int timesTriggered = properties.getInt1(); String[] statePropertyNames = {"timesTriggered"}; Object[] statePropertyValues = {timesTriggered}; return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues); }
private Trigger buildJobDetail(Date jobStartTime, JobDetail jobDetail, ScheduleBuilder scheduleBuilder) { return newTrigger() .withIdentity(triggerKey(EMPTY_TRASH_JOB, JOB_GROUP_NAME)) .forJob(jobDetail) .withSchedule(scheduleBuilder) .startAt(jobStartTime) .build(); }
private static ScheduleBuilder<? extends Trigger> parseAtExpr(String atExpr) { Matcher matcher = atExprPattern.matcher(atExpr); if (!matcher.matches()) throw new RuntimeException(atExpr + " is not valid"); if (matcher.group(1).equals("??")) { return CronScheduleBuilder.cronSchedule("0 " + matcher.group(2) + " * * * ?"); } DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm"); DateTime dateTime = formatter.parseDateTime(matcher.group().trim()); return CronScheduleBuilder.dailyAtHourAndMinute(dateTime.getHourOfDay(), dateTime.getMinuteOfHour()); }
private static ScheduleBuilder<? extends Trigger> parseEveryExpr(String everyExpr) { Matcher matcher = everyExprPattern.matcher(everyExpr); if (!matcher.matches()) throw new RuntimeException(everyExpr + " is not valid"); int num = Integer.parseInt(matcher.group(1)); if (num <= 0) throw new RuntimeException(everyExpr + " is not valid"); char unit = matcher.group(2).charAt(0); TimeUnit timeUnit = TimeUnit.MILLISECONDS; switch (unit) { case 'h': case 'H': timeUnit = TimeUnit.HOURS; break; case 'm': case 'M': timeUnit = TimeUnit.MINUTES; break; case 's': case 'S': timeUnit = TimeUnit.SECONDS; break; default: } return SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds((int) timeUnit.toSeconds(num)) .repeatForever(); }
public TriggerPropertyBundle(ScheduleBuilder<?> sb, String[] statePropertyNames, Object[] statePropertyValues) { this.sb = sb; this.statePropertyNames = statePropertyNames; this.statePropertyValues = statePropertyValues; }
public ScheduleBuilder<?> getScheduleBuilder() { return sb; }
@Override public ScheduleBuilder<?> getScheduleBuilder() { return CronScheduleBuilder.dailyAtHourAndMinute(0, 0); }
@Override public ScheduleBuilder<OnDemandTrigger> getScheduleBuilder() { return OnDemandScheduleBuilder.onDemandSchedule(); }
private ScheduleBuilder<? extends Trigger> parseCron(String schedulerExpr) { return cronSchedule(schedulerExpr); }
private ScheduleBuilder<? extends Trigger> throwException(String everyExpr) { throw new WestCacheException(everyExpr + " is not valid"); }
private Scheduler createUpdateWeatherDataScheduler(int interval, TimeUnit unit, ResourceBinder resourceBinder, int startDelay) throws SchedulerException, IOException, URISyntaxException { StdSchedulerFactory schedulerFactory = new StdSchedulerFactory(); Properties properties = new Properties(); properties.setProperty("org.quartz.threadPool.threadCount", String.valueOf(1)); schedulerFactory.initialize(properties); Scheduler scheduler = schedulerFactory.getScheduler(); JobDetail job = JobBuilder.newJob(UpdateWeatherData.class).build(); job.getJobDataMap().put("baseDir", ResourceBinder .getDataDir(this.getClass()).toFile().getCanonicalPath()); job.getJobDataMap().put("resourceBinder", resourceBinder); int secs = 60; switch (unit) { case HOUR: secs = interval * 60 * 60; break; case MINUTE: secs = interval * 60; case SECOND: secs = interval; break; default: break; } ScheduleBuilder<SimpleTrigger> scheduleBuilder = SimpleScheduleBuilder .simpleSchedule().withIntervalInSeconds(secs).repeatForever(); TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger() .withIdentity("trigger1", "group1"); if (startDelay < 1) triggerBuilder.startNow(); else triggerBuilder.startAt( DateBuilder.futureDate(startDelay, IntervalUnit.SECOND)); Trigger trigger = triggerBuilder.withSchedule(scheduleBuilder).build(); scheduler.scheduleJob(job, trigger); return scheduler; }
/** * @warn method description missing * * @return */ @Override @JsonIgnore public ScheduleBuilder getScheduleBuilder() { return cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing().inTimeZone(TimeZone.getTimeZone(timeZoneId)); }
public PollingEndpointQuartzBridgeTrigger(Scheduler scheduler, ScheduleBuilder scheduleBuilder) { Assert.notNull(scheduler, "scheduler is required"); Assert.notNull(scheduleBuilder, "scheduleBuilder is required"); this.scheduler = scheduler; this.scheduleBuilder = scheduleBuilder; }
private void scheduleRepeatingJob(RepeatingSchedulableJob job, boolean update) { logObjectIfNotNull(job); validateRepeatingSchedulableJob(job); MotechEvent motechEvent = job.getMotechEvent(); DateTime jobStartTime = job.getStartDate(); DateTime jobEndTime = job.getEndDate(); Integer repeatIntervalInSeconds = job.getRepeatIntervalInSeconds(); Integer jobRepeatCount = job.getRepeatCount(); if (null == jobRepeatCount) { jobRepeatCount = MAX_REPEAT_COUNT; } JobId jobId = new RepeatingJobId(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)); try { if (scheduler.getTrigger(triggerKey(jobId.value(), JOB_GROUP_NAME)) != null) { unscheduleJob(jobId); } } catch (SchedulerException e) { throw new MotechSchedulerException(format("Schedule or reschedule the job: %s.\n%s", jobId, e.getMessage()), "scheduler.error.cantRescheduleJob", Arrays.asList(jobId.value(), e.getMessage()), e); } ScheduleBuilder scheduleBuilder; if (!job.isUseOriginalFireTimeAfterMisfire()) { SimpleScheduleBuilder simpleSchedule = simpleSchedule() .withIntervalInSeconds(repeatIntervalInSeconds) .withRepeatCount(jobRepeatCount); simpleSchedule = setMisfirePolicyForSimpleTrigger(simpleSchedule, schedulerSettings.getProperty("scheduler.repeating.trigger.misfire.policy")); scheduleBuilder = simpleSchedule; } else { if (job.getRepeatCount() != null) { final double half = 0.5; jobEndTime = new DateTime((long) (job.getStartDate().getMillis() + repeatIntervalInSeconds * MILLISECOND * (job.getRepeatCount() + half))); } scheduleBuilder = CalendarIntervalScheduleBuilder.calendarIntervalSchedule() .withIntervalInSeconds(repeatIntervalInSeconds) .withMisfireHandlingInstructionFireAndProceed(); } Trigger trigger = buildJobDetail(job, DateUtil.toDate(jobStartTime), DateUtil.toDate(jobEndTime), jobId, jobDetail, scheduleBuilder); scheduleJob(jobDetail, trigger, update); }
public ScheduleBuilder<? extends Trigger> getScheduleBuilder() { return scheduleBuilder; }
/** * @warn method description missing * * @return */ public abstract ScheduleBuilder getScheduleBuilder();
public abstract ScheduleBuilder<T> getScheduleBuilder();
ScheduleBuilder<?> getScheduleBuilder();