Hi, I need to do some database housekeeping periodically. Right now I have a method in my model, which I am calling from ./script/console like x = Model.update_all and it works fine. I need to put this in cron. I know that I should be using ./script/runner, I have looked a lot for an example script encapsulating my method to do this. But could not find any. It would be great if some one can post a simple script that I can call from cron. I am also not sure if ./script/runner calls methods in my controller or model. thanks and regards, raj --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
script/runner will run model methods like this script/runner -e production ''Emailer.send_daily_announcements'' Be aware that script/runner loads the Rails framework every time it runs, so it starts slow. I.E. don''t use it for jobs that you run all the time. For a database monitoring daemon that runs a simple query every 5 seconds, I use a daemon that starts with ''./script/runner .... &'' and runs constantly - the method that I call has an infinite loop. This way the environment only loads once. Jason Rajkumar S wrote:> Hi, > > I need to do some database housekeeping periodically. Right now I have > a method in my model, which I am calling from ./script/console like x > = Model.update_all and it works fine. > > I need to put this in cron. I know that I should be using > ./script/runner, I have looked a lot for an example script > encapsulating my method to do this. But could not find any. It would > be great if some one can post a simple script that I can call from > cron. > > I am also not sure if ./script/runner calls methods in my controller or model. > > thanks and regards, > > raj > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s really simple - I use to create a new class located in model directory, eg : class Runner def self.run_it # do your stuff, activerecord models are available end end then in the cron.daily (or whatever) : #!/bin/sh /usr/local/www/my_ror_application/script/runner Runner.run_it -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you are on a Mac the following: couldn''t get it to work either. so check this guys post because I owe him a Heineken http://uberhamster.com/2006/9/12/invoking-ruby-on-rails-commands-via-cron-and-script-runner Now if someone has the answer why its got to be a full path let us know thanx -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter wrote:> If you are on a Mac the following: > > couldn''t get it to work either. > > so > > check this guys post because I owe him a Heineken > > http://uberhamster.com/2006/9/12/invoking-ruby-on-rails-commands-via-cron-and-script-runner > > Now if someone has the answer why its got to be a full path > let us knowFor DreamHost, and I expect for you too, the answer is that cron jobs are run with no environment (so no PATH). See here: http://wiki.dreamhost.com/index.php/Crontab regards Justin Forder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Totally clear ! Thanx -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks every one for the helpful mails! I am now able to run the Model method from command line. raj --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---