A simple, production-ready chronological scheduler for Redis. It allows you to schedule items to be processed at arbitrary points in the future, and easily retrieve only those items that are due to be processed.

It does everything you'd expect from a production scheduler:

  • You can schedule arbitrary items at arbitrary times.

  • You can iterate over ready items in either blocking or non-blocking mode.

  • It supports multiple concurrent producers and consumers.

  • An application exception causes the item to be rescheduled at the original time.

  • Work items lost as part of an application crash or segfault are recoverable.

In non-blocking mode, RedisScheduler#each will iterate over only those items whose scheduled time is less than or equal to the current time, and then stop. In blocking mode, RedisScheduler#each will additionally wait until further items are available. In nonblocking mode, #each will never return.

For debugging purposes, you can use RedisScheduler#items to iterate over all items in the queue. Note that this method is not guaranteed to be consistent in the presence of contemporaneous producers or consumers.

For error recovery purposes, you can use RedisScheduler#processing_set_items to iterate over all the items in the processing set to determine whether any of them are the result of a process crash.

Synopsis

r = Redis.new
s = RedisScheduler.new r, blocking: true
startt = Time.now
s.schedule! "a", startt + 10
s.schedule! "b", startt + 15
s.schedule! "c", startt + 20
s.each { |item, at| puts "#{Time.now - startt}: #{item}" }

prints:

10.03481788: a
15.05255288: b
20.06058172: c
... waits forever ...

Documentation

See RedisScheduler's #initiatilize, schedule! and #each methods.

Implementation

See masanjin.net/blog/using-redis-for-scheduling for some details.

Bug reports

Please file bugs here: github.com/wmorgan/redis-scheduler/issues Please send comments to: wmorgan-redis-scheduler-readme@masanjin.net.