Skip to content

Commit

Permalink
Track previousFireTime for triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
jlinn committed Mar 1, 2018
1 parent 47f1dc8 commit a381225
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public abstract class AbstractRedisStorage<T extends JedisCommands> {
* The name of the trigger hash property which stores the trigger's next fire time
*/
protected static final String TRIGGER_NEXT_FIRE_TIME = "nextFireTime";
/**
* Name of trigger hash property which stores the trigger's last fire time
*/
protected static final String TRIGGER_PREVIOUS_FIRE_TIME = "previousFireTime";

protected final RedisJobStoreSchema redisSchema;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ public List<TriggerFiredResult> triggersFired(List<OperableTrigger> triggers, Je
jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, "");
unsetTriggerState(triggerHashKey, jedis);
}
jedis.hset(triggerHashKey, TRIGGER_PREVIOUS_FIRE_TIME, Long.toString(System.currentTimeMillis()));

results.add(new TriggerFiredResult(triggerFiredBundle));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ public List<TriggerFiredResult> triggersFired(List<OperableTrigger> triggers, Je
jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, "");
unsetTriggerState(triggerHashKey, jedis);
}
jedis.hset(triggerHashKey, TRIGGER_PREVIOUS_FIRE_TIME, Long.toString(System.currentTimeMillis()));

results.add(new TriggerFiredResult(triggerFiredBundle));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.joelinn.junit.Retry;
import net.joelinn.junit.RetryRule;
import net.joelinn.quartz.jobstore.RedisJobStoreSchema;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -16,16 +17,15 @@
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import static junit.framework.TestCase.fail;
import static net.joelinn.quartz.TestUtils.createCronTrigger;
import static net.joelinn.quartz.TestUtils.createJob;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;

/**
* @author Joe Linn
Expand Down Expand Up @@ -113,6 +113,12 @@ public void testMultipleSchedulers() throws Exception {
try (Jedis jedis = jedisPool.getResource()) {
assertThat(jedis.get(KEY_ID), equalTo(scheduler2.getSchedulerInstanceId()));
}

List<? extends Trigger> triggers = scheduler2.getTriggersOfJob(job.getKey());
assertThat(triggers, Matchers.hasSize(greaterThan(0)));
for (Trigger t : triggers) {
assertThat(t.getPreviousFireTime(), notNullValue());
}
}


Expand Down

0 comments on commit a381225

Please sign in to comment.