Douglass Turner
2006-Jun-16 01:29 UTC
[Rails] How to pass params to long running system call
Hello, Can someone tell me the best way to make a system call (from within my model) that runs for a while and requires params form my model, specifically attributes of my model. So, I need the correct syntax and also general guidelines for launching the process. Thanks so much. Regards, Doug -- Posted via http://www.ruby-forum.com/.
Jason Roelofs
2006-Jun-16 01:43 UTC
[Rails] How to pass params to long running system call
Could you be a little more specific? Like which OS, which system call, and what do you mean by ''runs for a while''. The question is kind of vague. Jason Douglass Turner wrote:> Hello, > > Can someone tell me the best way to make a system call (from within my > model) that runs for a while and requires params form my model, > specifically attributes of my model. > > So, I need the correct syntax and also general guidelines for launching > the process. > > Thanks so much. > > Regards, > Doug > >
Douglass Turner
2006-Jun-16 02:07 UTC
[Rails] Re: How to pass params to long running system call
Jason Roelofs wrote:> Could you be a little more specific? Like which OS, which system call, > and what do you mean by ''runs for a while''. The question is kind of > vague. > > JasonI''m running on linux and intend to call good ole system(). The call is to a perl script that could run anywhere from a 5 seconds to 60 seconds. -Doug -- Posted via http://www.ruby-forum.com/.
Jason Roelofs
2006-Jun-16 02:38 UTC
[Rails] Re: How to pass params to long running system call
Douglass Turner wrote:> Jason Roelofs wrote: > >> Could you be a little more specific? Like which OS, which system call, >> and what do you mean by ''runs for a while''. The question is kind of >> vague. >> >> Jason >> > > I''m running on linux and intend to call good ole system(). The call is > to a perl script that could run anywhere from a 5 seconds to 60 seconds. > > -Doug > >If you don''t care about the return value of this script, then this should work: fork { exec("perl_script.pl") } Otherwise, throw a Ruby thread out and system() it. script_return = 0 Thread.new { script_return = system("perl_script.pl"); }.run Though please correct me if I''m wrong, but that should get you going. Jason
Rodney Ramdas
2006-Jun-16 05:02 UTC
[Rails] Re: How to pass params to long running system call
that''ll work but do look in to DRb: http://backgroundrb.rubyforge.org/ /r/r On 6/16/06, Jason Roelofs <jameskilton@gmail.com> wrote:> Douglass Turner wrote: > > Jason Roelofs wrote: > > > >> Could you be a little more specific? Like which OS, which system call, > >> and what do you mean by ''runs for a while''. The question is kind of > >> vague. > >> > >> Jason > >> > > > > I''m running on linux and intend to call good ole system(). The call is > > to a perl script that could run anywhere from a 5 seconds to 60 seconds. > > > > -Doug > > > > > If you don''t care about the return value of this script, then this > should work: > > fork { > exec("perl_script.pl") > } > > Otherwise, throw a Ruby thread out and system() it. > > script_return = 0 > Thread.new { > script_return = system("perl_script.pl"); > }.run > > Though please correct me if I''m wrong, but that should get you going. > > Jason > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Rodney http://www.pinupgeek.com http://www.dutchrailers.org
Ezra Zygmuntowicz
2006-Jun-16 06:27 UTC
[Rails] Re: How to pass params to long running system call
On Jun 15, 2006, at 7:38 PM, Jason Roelofs wrote:> Douglass Turner wrote: >> Jason Roelofs wrote: >> >>> Could you be a little more specific? Like which OS, which system >>> call, >>> and what do you mean by ''runs for a while''. The question is kind of >>> vague. >>> >>> Jason >>> >> >> I''m running on linux and intend to call good ole system(). The >> call is >> to a perl script that could run anywhere from a 5 seconds to 60 >> seconds. >> >> -Doug >> >> > If you don''t care about the return value of this script, then this > should work: > > fork { > exec("perl_script.pl") > }Don''t fork in your rails app. you will lose the database connection.> > Otherwise, throw a Ruby thread out and system() it. > > script_return = 0 > Thread.new { > script_return = system("perl_script.pl"); > }.run > > Though please correct me if I''m wrong, but that should get you going. > > JasonWhile that may work, it won''t be very happy about it ;) Especially if you are trying to run a perl script that takes as long as you are talking about. This is exactly the kind of thing I wrote backgroundrb [1] for. You should check it out.\ Cheers- -Ezra [1] http://backgroundrb.rubyforge.org
Douglass Turner
2006-Jun-16 10:23 UTC
[Rails] Re: Re: How to pass params to long running system call
Ezra Zygmuntowicz wrote:> On Jun 15, 2006, at 7:38 PM, Jason Roelofs wrote: > >>> >> >> fork { >> exec("perl_script.pl") >> } > > Don''t fork in your rails app. you will lose the database connection. > > >> Jason > While that may work, it won''t be very happy about it ;) Especially if > you are trying to run a perl script that takes as long as you are > talking about. This is exactly the kind of thing I wrote backgroundrb > [1] for. You should check it out.\ > > Cheers- > -Ezra > > [1] http://backgroundrb.rubyforge.orgEzra, I''m definitely going to check out backgroundrb. Wow, looks like a very good fit for my needs. Quick question, I notice you have methods in a controller class to handle launching jobs, progress bar, etc. What I envision is to launch a job and then simply have the job send an email to a particular address when it completes. Real simple. Are there any issues with backgroundrb if I want use this approach? Thanks again for this, Doug -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jun-16 14:57 UTC
[Rails] Re: Re: How to pass params to long running system call
On Jun 16, 2006, at 3:23 AM, Douglass Turner wrote:> Ezra Zygmuntowicz wrote: >> On Jun 15, 2006, at 7:38 PM, Jason Roelofs wrote: >> >>>> >>> >>> fork { >>> exec("perl_script.pl") >>> } >> >> Don''t fork in your rails app. you will lose the database connection. >> >> >>> Jason >> While that may work, it won''t be very happy about it ;) Especially if >> you are trying to run a perl script that takes as long as you are >> talking about. This is exactly the kind of thing I wrote backgroundrb >> [1] for. You should check it out.\ >> >> Cheers- >> -Ezra >> >> [1] http://backgroundrb.rubyforge.org > > Ezra, > > I''m definitely going to check out backgroundrb. Wow, looks like a very > good fit for my needs. Quick question, I notice you have methods in a > controller class to handle launching jobs, progress bar, etc. What I > envision is to launch a job and then simply have the job send an email > to a particular address when it completes. Real simple. Are there any > issues with backgroundrb if I want use this approach? > > Thanks again for this, > DougHey Doug- Yeah what you want to do would be no problem. You aren''t forced to use progress bars at all. In fact you can use the plugin like a fire and forget type of thing. I mean if you just kick it off from your rails app somewhere, then it can just do its thing and then send the email. You will want to run a simple cron script that does garbage collection of old worker instances every so often. The next major release will introduce a timing mechanism so old workers get garbage collected automatically. Or you will be able to set a time to live when you start the worker and it will commit suicide after the time runs out. There''s ifo abou ll of this stuff in the README as well as a script you can run from cron. Cheers- -Ezra