rufus-runner
Wraps rufus-scheduler in a standalone process, with job timing, logging, and safe defaults.
Note: I did not write this gem, only deployed it to RubyGems. The project appears to be dead and I'll provide support the best I can. If the original authors decide they want to take it back over, just let me know.
Forked from: https://github.com/HouseTrip/rufus-runner
Installation
Add this line to your application's Gemfile:
gem 'rufus-runner'
$ bundle
Or install it yourself as:
$ gem install rufus-runner
Create a configuration file:
# config/schedule.rb
Rufus::TrackingScheduler.start do |scheduler|
# sentinel job that keeps running to prove Rufus is still alive
scheduler.run :name => 'no-op', :every => '60s' do
Kernel.sleep(1e-3)
end
end
The #run
method simply takes the same options as Rufus's #every
method,
with these safe defaults:
:mutex => <m> # because Rails is not thread-safe
:timeout => 60 # we don't want no long-running jobs, they should be DJ'd (seconds)
:discard_past => true # don't catch up with past jobs
:allow_overlapping => false # don't try to run the same job twice simultaneously
Where <m>
is a shared, global instance of Mutex
.
Finally, run it:
$ rufus-runner config/schedule.rb
Rails
If you're running Rails, you might want to have an environment loaded in the scheduler. Simply add on top of your schedule:
# Rails 2
require 'config/boot'
require 'config/environment'
# Rails 3
require 'config/application'
When Rails is present, rufus-runner
will call ActiveRecord::Base.clear_active_connections!
after each job for you.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request