[ANN] RailsCron 0.1 plugin


#1

I, like many of you, have been searching for a good way to handle
running long processes in Rails. So I rolled my own solution. I
really want feedback! (I’ve tested this on very simple hello world
examples, so don’t use it on anything production yet) .

Grab the plugin:
http://opensvn.csie.org/rails_cron

Here’s the README:

OVERVIEW

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:

  • Significant startup resources required
  • Lots of RAM to run simultaneous processes
  • Hard to start/stop/affect the background processes from within Rails.

RailsCron addresses these shortcomings by using one RoR instance with
threading (Ruby, native to be added later).

STARTING & STOPPING

RailsCron is started and stopped by Rake. List of Rake tasks:

  • cron_start – Starts RailsCron as a daemon
  • cron_foreground – Starts RailsCron in the foreground
  • cron_stop – Graceful stop
  • cron_kill
  • cron_graceful – Graceful restart
  • cron_status

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:

  • USER – The background job will run as this user. Default: current
    user
  • RAILS_ENV – Default: development
  • SLEEP – Time to sleep between checking for jobs Default: 1 second

INSTALLATION

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.

BUGS & FEEDBACK

Bug reports (as well as patches) and feedback are very welcome. Please
send it to
removed_email_address@domain.invalid


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
removed_email_address@domain.invalid
1-866-263-3261


#2

On Jan 6, 2006, at 6:43 PM, Kyle M. wrote:

OVERVIEW
:finish => 2.years.from_now # optional

  • Hard to start/stop/affect the background processes from within
  • cron_start – Starts RailsCron as a daemon

RailsCron is a standard Ruby on Rails plugin. For information about
send it to
removed_email_address@domain.invalid

This is great stuff, Kyle! Thanks for making it public. I like the
‘auto-generated table’ technique in the plugin’s init.rb. Sure makes
integration simple :slight_smile:

I was looking over the code, trying to get a sense for what it all
does, and I’m still puzzled about one thing. Why start a whole new
process for the RailsCron work? Why not just untwine a thread in
environment.rb (i.e. when your rails app starts) and save on memory
there?

The angle I’m coming from is I’m developing an app that requires a
“background queue” for processing external web API services.
Del.icio.us, for example, has a max request rate of 1-per-second. If
my app gets busy, rather than blocking everyone, I’d like to queue
them up and process slowly if necessary. Do you think this is suited
for RailsCron? I’d rather not start something on the command line as
part of the “boot-up” process, since that’s often forgotten
(especially on a box not hosted by myself).

Thanks,
Duane J.
(canadaduane)
http://blog.inquirylabs.com/


#3

Did you guys take this discussion off line ?
If so, post it here ! If not, keep going !
:slight_smile:


#4

On 2/24/06, Dylan S. removed_email_address@domain.invalid wrote:

running long processes in Rails. So I rolled my own solution. I

  • cron_stop – Graceful stop

rails project.

Duane J.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Discussion has continued, as has development on the plugin (another
dozen or more revisions in the svn trunk) Just search the list for
RailsCron or rails_cron. Also, look at my blog at kylemaxwell.com.


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
removed_email_address@domain.invalid
1-866-263-3261