Continuity

NOTE: this has a decent amount of test coverage, but has yet to be tested in any kind of production environment. I hope to do some more real-worldish testing soon.

Allows you to share scheduling duties across any number of workers. Unlike other solutions (clockwork/rufus-scheduler) it doesn’t introduce a single point of failure rely by relying on a single, always running scheduling process. Workers use Redis to coordinate scheduling duties. The scheduler will never miss a job, even if all workers are shut down for a period of time it will pick up from where it left off

Continuity only runs one job at a time, so your tasks should create jobs in Resque, DJ, etc and not actually do the heavy lifting themselves.

Redis could conceivably be replaced by any consistent datastore.

Example

scheduler = Continuity::Scheduler.new_using_redis(redis_handle)

scheduler.every('10s') do
  Resque.enqueue(PeriodicJob)
end

scheduler.cron('0 0 * * * *') do
  Resque.enqueue(DailyJob)
end

scheduler.cron('0 * * * *') do
  Resque.enqueue(DailyJob)
end

# main worker loop
loop do
  do_job
  scheduler.maybe_schedule
end

Cron

On Schedule Hook

scheduler.on_schedule do |range|
  delayed_jobs = $redis.zrangebyscore(:delayed_jobs, range.first, range.last)
  delayed_jobs.each do |job|
    do_it(job)
  end
end

Contributing to continuity

Copyright © 2010 Bob Potter. See LICENSE.txt for further details.