Skip to content

Instantly share code, notes, and snippets.

@kehati
Last active January 4, 2016 13:59
Show Gist options
  • Save kehati/8631711 to your computer and use it in GitHub Desktop.
Save kehati/8631711 to your computer and use it in GitHub Desktop.
RedisJobStore readme

RedisJobStore

A Quartz Scheduler JobStore, that utilizes redis as a persistent storage.

Configuration

To get Quartz up and running quickly with RedisJobStore, use the following example to configure your quartz.properties file:

# setting the scheduler's misfire threshold, in milliseconds 
org.quartz.jobStore.misfireThreshold: 60000

# setting the scheduler's JobStore to RedisJobStore
org.quartz.jobStore.class: com.garantia.quartz.RedisJobStore

# setting your redis host
org.quartz.jobStore.host: <your_redis_host>

# setting your redis port
org.quartz.jobStore.port: <your_redis_port>

# setting your redis password (optional)
org.quartz.jobStore.password: <your_redis_password>

# setting a 'releaseTriggersInterval' will trigger a mechanism for releasing triggers of non-alive schedulers in a given interval, in milliseconds
org.quartz.jobStore.releaseTriggersInterval: 600000

# setting a path for writing the scheduler's id, in order to release triggers of previous schedulers on startup
org.quartz.jobStore.instanceIdFilePath: /var/lib/quartz

External Libraries

RedisJobStore is using jedis and gson libraries, so you'll have to download them and add them to your project's classpath, or use them as maven dependencies:

<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
	<version>2.0.0</version>
</dependency>

<dependency>
 	<groupId>com.google.code.gson</groupId>
 	<artifactId>gson</artifactId>
 	<version>2.2.4</version>
</dependency>

Limitations

RedisJobStore is eager to fully comply with all Quartz features, but currently has some limitations that you should be aware of:

  • Only SimpleTrigger and CronTriggerare supported.
  • For any GroupMatcher, only a StringOperatorName.EQUALS operator is supported. You should note that if your scheduler is designed to compare any group of jobs, triggers, etc. with a pattern-based matcher.
  • RedisJobStore is designed to use multiple schedulers, but it is not making any use of the org.quartz.scheduler.instanceName. The only limitation here is that you should maintain the uniquness of your trigger_group_name:trigger_name, and your job_group_name:job_name and you'll be good to go with multiple schedulers.
  • A Scheduler should be started once on a machine, also to ensure releasing locked triggers of previously crashed schedulers.
  • Data atomicity- RedisJobStore is not using any transaction-like mechanism, but ensures synchronization with global lockings. As a result, if a connection issue occurs during an operation, it might be partially completed.
  • JobDataMap values are stored and returned as Strings, so you should implement your jobs accordingly.
  • RedisJobStore is firing triggers only by their fire time, without any cosideration to their priorities at all.

Known Issues

  1. Quartz's standard JobStores are sometimes considering triggers without a next fire time as tirggers in a WAITING state. As RedisJobStore is using redis Sorted Sets to maintain triggers states, using their next fire time as the score, it will consider these triggers as stateless.

Redis Schema

To better understand the workflow and the behavior of a Quartz Scheduler using a RedisJobStore, you may want to review the redis schema in which the RedisJobStore is making a use of, at: add_schema_link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment