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 kyle@kylemaxwell.com -- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261
On Jan 6, 2006, at 6:43 PM, Kyle Maxwell wrote:> 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 > kyle@kylemaxwell.com >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 :) 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 Johnson (canadaduane) http://blog.inquirylabs.com/
Did you guys take this discussion off line ? If so, post it here ! If not, keep going ! :) On 1/9/06, Duane Johnson <duane.johnson@gmail.com> wrote:> > > On Jan 6, 2006, at 6:43 PM, Kyle Maxwell wrote: > > > 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 > > kyle@kylemaxwell.com > > > > 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 :) > > 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 Johnson > (canadaduane) > http://blog.inquirylabs.com/ > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060224/9df33d44/attachment-0001.html
On 2/24/06, Dylan Stamat <dylans@gmail.com> wrote:> Did you guys take this discussion off line ? > If so, post it here ! If not, keep going ! > :) > > On 1/9/06, Duane Johnson < duane.johnson@gmail.com> wrote: > > > > > > On Jan 6, 2006, at 6:43 PM, Kyle Maxwell wrote: > > > > > 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 > > > kyle@kylemaxwell.com > > > > > > > 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 :) > > > > 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 Johnson > > (canadaduane) > > http://blog.inquirylabs.com/ > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > 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 Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261