Hello, I need to put a script in place for updating a local database with a remote resource periodically. It should be started alongside the server (or inside it, whatever) and be run as long as the server running my rails app is up an running. Any thoughts on how to accomplish this? I have thought of editing the environment.rb file and placing the call to the script trigger there, but I wonder if this is a good design decision and if it is webserver-dependent. Cheers, Thiago Arrais
Hi ! 2006/2/23, Thiago Arrais <thiago.arrais@gmail.com>:> Hello, > > I need to put a script in place for updating a local database with a > remote resource periodically. It should be started alongside the > server (or inside it, whatever) and be run as long as the server > running my rails app is up an running.Take a look at RailsCron: http://svn.kylemaxwell.com/rails_cron/trunk/README Of course, cron itself can do that for you. Just schedule "script/runner" with some parameters that say what to do: 0 8,20 * * * * ruby script/runner production "ProductUpdator.update" Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/
Francois, On 2/23/06, Francois Beausoleil <francois.beausoleil@gmail.com> wrote:> Take a look at RailsCron: http://svn.kylemaxwell.com/rails_cron/trunk/READMEThanks for the pointer. But I still miss something. Where should I place the RailsCron call? For a first test, I have tried to define a class Printer for peridiodically printing to the standard output. It looked like this class Printer < ActiveRecord::Base background :print, :every => 1.minute def self.print puts "RailsCron called me at #{Time.now}" end end I did not install anything besides out-of-the-box rails, since the readme file says it is a standard Rails plugin. As you may see, I have read ''standard'' as ''bundled with the standard installation''. Maybe I am wrong here? I started the webrick server with ruby script/server and the class didn''t get called (just like I expected, no magic happened). The readme file says that cron can be started and stopped by rake, but what I would really like was to start it whenever the server is started. Should I modify my environment scripts? Is there any other (more appropiate) startup script for a Rails app or I am seriously misguided here? Thanks in advance, Thiago Arrais
Hi ! 2006/2/24, Thiago Arrais <thiago.arrais@gmail.com>:> I started the webrick server with ruby script/server and the class > didn''t get called (just like I expected, no magic happened). The > readme file says that cron can be started and stopped by rake, but > what I would really like was to start it whenever the server is > started. Should I modify my environment scripts? Is there any other > (more appropiate) startup script for a Rails app or I am seriously > misguided here?I haven''t used the plugin myself. I just knew about it. After reading the docs, I guess you need to start the plugin through Rake. As you mention, environment.rb seems like the right place to do it. Hope that helps, -- Fran?ois Beausoleil http://blog.teksol.info/
On 2/24/06, Thiago Arrais <thiago.arrais@gmail.com> wrote:> Francois, > > On 2/23/06, Francois Beausoleil <francois.beausoleil@gmail.com> wrote: > > Take a look at RailsCron: http://svn.kylemaxwell.com/rails_cron/trunk/README > > Thanks for the pointer. But I still miss something. > > Where should I place the RailsCron call? For a first test, I have > tried to define a class Printer for peridiodically printing to the > standard output. It looked like this > > class Printer < ActiveRecord::Base > background :print, :every => 1.minute > > def self.print > puts "RailsCron called me at #{Time.now}" > end > end > > I did not install anything besides out-of-the-box rails, since the > readme file says it is a standard Rails plugin. As you may see, I have > read ''standard'' as ''bundled with the standard installation''. Maybe I > am wrong here?You also need to execute the following command from the RAILS_ROOT folder: ./script/plugin install http://svn.kylemaxwell.com/rails_cron/trunk> > I started the webrick server with ruby script/server and the class > didn''t get called (just like I expected, no magic happened). The > readme file says that cron can be started and stopped by rake, but > what I would really like was to start it whenever the server is > started. Should I modify my environment scripts? Is there any other > (more appropiate) startup script for a Rails app or I am seriously > misguided here?1. You need to add require_dependency "printer" to your environment.rb. Otherwise, the action will start the first time your program calls for the class, as the class is not loaded until it is needed. Also, you need to execute the command "rake cron_start" This initializes the background process. Use "rake cron_graceful" to restart the process. To automatically execute this at the same time as the server restarts, I reccommend writing a SwitchTower script.> > Thanks in advance, > > Thiago Arrais > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261