Java Code Examples for org.quartz.spi.OperableTrigger#updateAfterMisfire()
The following examples show how to use
org.quartz.spi.OperableTrigger#updateAfterMisfire() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobStoreSupport.java From lams with GNU General Public License v2.0 | 6 votes |
private void doUpdateOfMisfiredTrigger(Connection conn, OperableTrigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException { Calendar cal = null; if (trig.getCalendarName() != null) { cal = retrieveCalendar(conn, trig.getCalendarName()); } schedSignaler.notifyTriggerListenersMisfired(trig); trig.updateAfterMisfire(cal); if (trig.getNextFireTime() == null) { storeTrigger(conn, trig, null, true, STATE_COMPLETE, forceState, recovering); schedSignaler.notifySchedulerListenersFinalized(trig); } else { storeTrigger(conn, trig, null, true, newStateIfNotComplete, forceState, false); } }
Example 2
Source File: JobStoreImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Determine if trigger has misfired. */ private boolean applyMisfire(final ODatabaseDocumentTx db, final TriggerEntity triggerEntity) { log.trace("Checking for misfire: {}", triggerEntity); OperableTrigger trigger = triggerEntity.getValue(); long misfireTime = getMisfireTime(); Date nextFireTime = trigger.getNextFireTime(); if (nextFireTime == null || nextFireTime.getTime() > misfireTime || trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) { return false; } // resolve trigger calender if there is one Calendar calendar = null; if (trigger.getCalendarName() != null) { calendar = findCalendar(db, trigger.getCalendarName()); } signaler.notifyTriggerListenersMisfired(trigger); trigger.updateAfterMisfire(calendar); if (trigger.getNextFireTime() == null) { triggerEntity.setState(COMPLETE); triggerEntityAdapter.editEntity(db, triggerEntity); signaler.notifySchedulerListenersFinalized(trigger); } else if (nextFireTime.equals(trigger.getNextFireTime())) { return false; } return true; }
Example 3
Source File: JobStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Simulate a job that has run longer than the next fire time such that it misfires. */ @Test public void testTriggerPastDueMisfire() throws Exception { JobDetail jobDetail = JobBuilder.newJob(MyNonConcurrentJob.class) .storeDurably(true) .build(); jobStore.storeJob(jobDetail, false); ZoneId zone = ZoneId.systemDefault(); Date baseFireTimeDate = DateBuilder.evenMinuteDateAfterNow(); LocalDateTime baseDateTime = LocalDateTime.ofInstant(baseFireTimeDate.toInstant(), zone); LocalDateTime startAt = baseDateTime.minusMinutes(5); LocalDateTime nextFireTime = startAt.plusMinutes(1); CronScheduleBuilder schedule = CronScheduleBuilder.cronSchedule("0 1 * * * ? *"); OperableTrigger trigger = (OperableTrigger) TriggerBuilder.newTrigger() .forJob(jobDetail) .withSchedule(schedule) .startAt(Date.from(startAt.atZone(zone).toInstant())) .build(); // misfire the trigger and set the next fire time in the past trigger.updateAfterMisfire(null); trigger.setNextFireTime(Date.from(nextFireTime.atZone(zone).toInstant())); jobStore.storeTrigger(trigger, false); List<OperableTrigger> acquiredTriggers = jobStore.acquireNextTriggers(DateBuilder.evenMinuteDateAfterNow().getTime(), 4, 1000L); assertEquals(1, acquiredTriggers.size()); }
Example 4
Source File: JobStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Simulate a job that has run longer than the next fire time such that it misfires, but will not fire again because * the end of the trigger window has passed. */ @Test public void testTriggerPastDueMisfireButWillNotFire() throws Exception { JobDetail jobDetail = JobBuilder.newJob(MyNonConcurrentJob.class).storeDurably(true).build(); jobStore.storeJob(jobDetail, false); ZoneId zone = ZoneId.systemDefault(); Date baseFireTimeDate = DateBuilder.evenMinuteDateAfterNow(); LocalDateTime baseDateTime = LocalDateTime.ofInstant(baseFireTimeDate.toInstant(), zone); LocalDateTime startAt = baseDateTime.minusMinutes(5); LocalDateTime endAt = baseDateTime.minusMinutes(1); LocalDateTime nextFireTime = startAt.plusMinutes(1); SimpleScheduleBuilder simple = SimpleScheduleBuilder.simpleSchedule() .withIntervalInMinutes(1); OperableTrigger trigger = (OperableTrigger) TriggerBuilder.newTrigger() .forJob(jobDetail) .withSchedule(simple) .startAt(Date.from(startAt.atZone(zone).toInstant())) .endAt(Date.from(endAt.atZone(zone).toInstant())) .build(); // misfire the trigger and set the next fire time in the past trigger.updateAfterMisfire(null); trigger.setNextFireTime(Date.from(nextFireTime.atZone(zone).toInstant())); trigger.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT); jobStore.storeTrigger(trigger, false); List<OperableTrigger> acquiredTriggers = jobStore.acquireNextTriggers(baseFireTimeDate.getTime(), 4, 1000L); assertEquals(0, acquiredTriggers.size()); }
Example 5
Source File: AbstractRedisStorage.java From quartz-redis-jobstore with Apache License 2.0 | 5 votes |
/** * Determine whether or not the given trigger has misfired. * If so, notify the {@link org.quartz.spi.SchedulerSignaler} and update the trigger. * @param trigger the trigger to check for misfire * @param jedis a thread-safe Redis connection * @return false if the trigger has misfired; true otherwise * @throws JobPersistenceException */ protected boolean applyMisfire(OperableTrigger trigger, T jedis) throws JobPersistenceException { long misfireTime = System.currentTimeMillis(); if(misfireThreshold > 0){ misfireTime -= misfireThreshold; } final Date nextFireTime = trigger.getNextFireTime(); if(nextFireTime == null || nextFireTime.getTime() > misfireTime || trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY){ return false; } Calendar calendar = null; if(trigger.getCalendarName() != null){ calendar = retrieveCalendar(trigger.getCalendarName(), jedis); } signaler.notifyTriggerListenersMisfired((OperableTrigger) trigger.clone()); trigger.updateAfterMisfire(calendar); storeTrigger(trigger, true, jedis); if(trigger.getNextFireTime() == null){ setTriggerState(RedisTriggerState.COMPLETED, (double) System.currentTimeMillis(), redisSchema.triggerHashKey(trigger.getKey()), jedis); signaler.notifySchedulerListenersFinalized(trigger); } else if(nextFireTime.equals(trigger.getNextFireTime())){ return false; } return true; }
Example 6
Source File: RedisJobStore.java From redis-quartz with MIT License | 5 votes |
protected boolean applyMisfire(OperableTrigger trigger, Jedis jedis) throws JobPersistenceException { long misfireTime = System.currentTimeMillis(); if (getMisfireThreshold() > 0) misfireTime -= getMisfireThreshold(); Date triggerNextFireTime = trigger.getNextFireTime(); if (triggerNextFireTime == null || triggerNextFireTime.getTime() > misfireTime || trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) { return false; } Calendar cal = null; if (trigger.getCalendarName() != null) cal = retrieveCalendar(trigger.getCalendarName(), jedis); signaler.notifyTriggerListenersMisfired((OperableTrigger)trigger.clone()); trigger.updateAfterMisfire(cal); if (triggerNextFireTime.equals(trigger.getNextFireTime())) return false; storeTrigger(trigger, true, jedis); if (trigger.getNextFireTime() == null) { // Trigger completed setTriggerState(RedisTriggerState.COMPLETED, (double)System.currentTimeMillis(), createTriggerHashKey(trigger.getKey().getGroup(), trigger.getKey().getName())); signaler.notifySchedulerListenersFinalized(trigger); } return true; }