I could swear I''ve seen instructions before on how to do this, but I can''t find them. I''ve got a backend process that runs in the same environment as my webapp, injecting data into the model. In the interests of not repeating myself I''d like to take advantage of the app/models from my webapp as well as my config/database.yml information. Normally when running the script by hand I''d go into script/console and just do a ''require'' on it. This has served me quite nicely, actually. But I''ve got to put this into a cron job and take the people out of the loop. Is there a "right" way to do that, and simulate all those assumptions that the console has to make before running my script? As far as I can figure the console app does not have a standard "start up, run X script and then exit" option. I suppose I can just string together all the necessary requires at the top of my script, manually including the model files I need and such. I''m just trying to figure out if there''s a better/cleaner way already out there. [This feels like a FAQ and trust me, I''m googling as best I can and just not finding it! I hate asking when I feel like I should know the answer...] -- 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 -~----------~----~----~----~------~----~------~--~---
Go to your RAILS_ROOT folder and then: script/runner "here goes the name of your script" -e production Read the help: script/runner -h Usage: script/runner [options] (''Some.ruby(code)'' or a filename) -e, --environment=name Specifies the environment for the runner to operate under (test/development/production). Default: development -h, --help Show this help message. You can also use runner as a shebang line for your scripts like this: ------------------------------------------------------------- #!/usr/bin/env /home/mauricio/NetBeansProjects/something/script/runner Product.find(:all).each { |p| p.price *= 2 ; p.save! } ------------------------------------------------------------- - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Wed, Feb 25, 2009 at 12:57 PM, Duane Morin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I could swear I''ve seen instructions before on how to do this, but I > can''t find them. I''ve got a backend process that runs in the same > environment as my webapp, injecting data into the model. In the > interests of not repeating myself I''d like to take advantage of the > app/models from my webapp as well as my config/database.yml information. > > Normally when running the script by hand I''d go into script/console and > just do a ''require'' on it. This has served me quite nicely, actually. > > But I''ve got to put this into a cron job and take the people out of the > loop. Is there a "right" way to do that, and simulate all those > assumptions that the console has to make before running my script? As > far as I can figure the console app does not have a standard "start up, > run X script and then exit" option. I suppose I can just string > together all the necessary requires at the top of my script, manually > including the model files I need and such. I''m just trying to figure > out if there''s a better/cleaner way already out there. > > [This feels like a FAQ and trust me, I''m googling as best I can and just > not finding it! I hate asking when I feel like I should know the > answer...] > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Generally, you want to put this sort of thing in a rake task (instead of a script) and then your cron is just cd /application_rails_directory; rake do_my_thing --RAILS_ENV=production> On Wed, Feb 25, 2009 at 12:57 PM, Duane Morin > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> I could swear I''ve seen instructions before on how to do this, but I >> can''t find them. I''ve got a backend process that runs in the same >> environment as my webapp, injecting data into the model. In the >> interests of not repeating myself I''d like to take advantage of the >> app/models from my webapp as well as my config/database.yml information. >> >> Normally when running the script by hand I''d go into script/console and >> just do a ''require'' on it. This has served me quite nicely, actually. >> >> But I''ve got to put this into a cron job and take the people out of the >> loop. Is there a "right" way to do that, and simulate all those >> assumptions that the console has to make before running my script? As >> far as I can figure the console app does not have a standard "start up, >> run X script and then exit" option. I suppose I can just string >> together all the necessary requires at the top of my script, manually >> including the model files I need and such. I''m just trying to figure >> out if there''s a better/cleaner way already out there. >> >> [This feels like a FAQ and trust me, I''m googling as best I can and just >> not finding it! I hate asking when I feel like I should know the >> answer...]--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---