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

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

Jason R. 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

Douglass T. wrote:

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

that’ll work but do look in to DRb:

http://backgroundrb.rubyforge.org/

/r/r

On 6/16/06, Jason R. [email protected] wrote:

I’m running on linux and intend to call good ole system(). The call is
}
Jason


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rodney
http://www.pinupgeek.com
http://www.dutchrailers.org

On Jun 15, 2006, at 7:38 PM, Jason R. 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 :wink: 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 Z. wrote:

On Jun 15, 2006, at 7:38 PM, Jason R. 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 :wink: 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,
Doug

On Jun 16, 2006, at 3:23 AM, Douglass T. wrote:

[1] http://backgroundrb.rubyforge.org
Thanks again for this,
Doug

Hey 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