I think the aanswer to my question is yes, but I will ask it nyways. I want ot have a ruby program that will process rows in my database at midnight every nite. If I have a ruby program that is kicked off by cron can I use active records inside it? thanks, scott. -- Scott F. Walter Scott F. Walter Principal Consultant Vivare, Inc. E: scott.walter-uosFFu51klvQT0dZR+AlfA@public.gmane.org E: scott-APWf0AbNa2kIjDr1QQGPvw@public.gmane.org Visit scottwalter.com <http://scottwalter.com> --Point. Click. Explore!
On 8/23/05, Scott F. Walter <scott.walter-uosFFu51klvQT0dZR+AlfA@public.gmane.org> wrote:> I think the aanswer to my question is yes, but I will ask it nyways. I > want ot have a ruby program that will process rows in my database at > midnight every nite. If I have a ruby program that is kicked off by > cron can I use active records inside it? > > thanks, scott. > --Yes. You can just require ''active_record'' (and ruby gems), but you have to set the configuration stuff yourself. I''m assuming this is a script that runs next to your rails app. In this case, it''s simpler to just require environment.rb. If you want observers to fire also (to send off your emails, for example) be sure to add this: UserObserver.instance # this awakens the sleeping observer User.find(1).save # sample code to save a user, or something, fires off any observer callbacks Take a look at script/runner for any super simple one liners. You can pass the oneliner straight to it... -- rick http://techno-weenie.net
Scott F. Walter wrote:> I think the aanswer to my question is yes, but I will ask it nyways. > I want ot have a ruby program that will process rows in my database at > midnight every nite. If I have a ruby program that is kicked off by > cron can I use active records inside it?Absolutely. If your database (a) has synthetic primary keys and (b) follows some naming convention consstently (ideally, AR''s naming convention, but not necesarily so), it makes a nice little ORM. E.g., I use it in a functional test framework on the job right now. Alex
A look into the Wiki would have been the easiest: http://wiki.rubyonrails.com/rails/show/HowToUseActiveRecordThroughStandAloneScript Greetz, Martin Scott F. Walter wrote:> I think the aanswer to my question is yes, but I will ask it nyways. I > want ot have a ruby program that will process rows in my database at > midnight every nite. If I have a ruby program that is kicked off by > cron can I use active records inside it? > > thanks, scott.
> I think the aanswer to my question is yes, but I will ask it nyways. I > want ot have a ruby program that will process rows in my database at > midnight every nite. If I have a ruby program that is kicked off by > cron can I use active records inside it?For CRON-powered programs, you might want to look into using script/runner, which can be used like this: ./script/runner ''BillingService.run'' That would start the BillingService inside of the relevant environment with everything setup. That way you can have your "scripts" just be service models that include everything in an object-oriented fashion. -- David Heinemeier Hansson http://www.loudthinking.com -- Broadcasting Brain http://www.basecamphq.com -- Online project management http://www.backpackit.com -- Personal information manager http://www.rubyonrails.com -- Web-application framework