You are here: Browse Railsplugins Rails Cron 0.2.2
RailsCron is a way to execute background tasks using your Ruby on Rails environment. The RailsCron object is an ActiveRecord, so you can manipulate it in familiar ways:
RailsCron.create(
:command => "Object.do_something()",
:start => 2.minutes.from_now,
:every => 12.hours, # default: 1.day
:finish => 2.years.from_now # optional
)
RailsCron.destroy_all
RailsCron.find_by_command "some_command"
Cron, when used with RoR, has the following shortcomings:
RailsCron addresses these shortcomings by using one RoR instance with threading (Ruby, native to be added later).
RailsCron will let you designate a class method of an ActiveRecord model (or another class that includes ActsAsBackground) to be run in the background. This is useful for asynchronous processing of things like email queues. Note that by default, only one background thread of a given method will be running at any time (override with :concurrent => true).
class EmailQueue < ActiveRecord::Base
background :deliver, :every => 1.minute, :concurrent => true
end
def self.deliver
#process the queue
end
RailsCron is started and stopped by Rake. List of Rake tasks:
These commands are UNIX-oriented. Windows users can start with “ruby script\runner ‘RailsCron.start’” and stop with Ctrl-C. I have no idea (or need) of how to make this a Windows service, but the patch would be welcome.
The following environment variables are used by the Rake tasks:
RailsCron is a standard Ruby on Rails plugin. For information about how to install plugins, type “ruby script/plugin—help” from within a rails project.
RailsCron will add a table called ‘rails_crons’ to your database(s), if it does not already exist.
Bug reports (as well as patches) and feedback are very welcome. Please send it to kyle@kylemaxwell.com
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly