Java Code Examples for org.quartz.spi.OperableTrigger#getMisfireInstruction()

The following examples show how to use org.quartz.spi.OperableTrigger#getMisfireInstruction() . 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: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 2
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private boolean canBeAcquired(final TriggerEntity entity,
                              final ODatabaseDocumentTx db,
                              final long timeWindowStart,
                              final long timeWindowEnd)
{
  OperableTrigger trigger = entity.getValue();

  // skip triggers which have no next fire time
  if (trigger.getNextFireTime() == null) {
    return false;
  }

  // skip triggers which match misfire fudge logic (if the trigger will no longer fire)
  // NOTE: applyMisfire(...) may modify trigger.getNextFireTime()
  if (applyMisfire(db, entity) && trigger.getNextFireTime() == null) {
    return false;
  }

  // skip triggers which fire outside of requested window
  if (trigger.getNextFireTime().getTime() > timeWindowEnd) {
    return false;
  }

  // skip triggers which fire outside of requested window
  if (trigger.getMisfireInstruction() != Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY &&
      trigger.getNextFireTime().getTime() < timeWindowStart) {
    return false;
  }

  // check after misfire logic to avoid repeated log-spam
  if (isClustered() && isLimitedToMissingNode(entity)) {
    return false;
  }

  return true;
}
 
Example 3
Source File: AbstractRedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
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;
}