Thread problems

I have a really long series of queries (import from other database*)
that takes about 2 or 3 minutes. I wanted to spawn a thread and put the
job there, but there seems to be some problems with active record and
threads: (this is what I found after googling)

Thread.abort_on_exception = true
=> true
100.times do
Thread.new do
Client.find(:first)
end
end

this throws an exception… So the question here: Is someone working on
this? if the answer is no, I will give it a try, because I really need
threads to be working on my app. If the answer is yes, who is working on
this? can I help you?.

  • the import is done this way: fetch some records using a webservice,
    check if the data is in my database, import the new records and delete
    the old ones. Due to requirements, this is the only way to do it.

regards,
rolando.-

On Aug 3, 2006, at 7:34 AM, Rolando A. wrote:

Client.find(:first)
  • the import is done this way: fetch some records using a webservice,
    check if the data is in my database, import the new records and delete
    the old ones. Due to requirements, this is the only way to do it.

regards,
rolando.-

Rolando-

Don't do that ;) You will only run into problems trying to use

threads that way within your rails applications. While some of the
parts of rails are sort of thread safe, the entire environment as a
whole is not thread safe. So you will get the errors that you are
currently getting. I wrote the BackgrounDRb[1] plugin for just this
type of problem. You can put the long tasks in another process in a
drb server and get status updates from within rails. Have a look and
see what you think.

Cheers-
-Ezra

[1] http://backgroundrb.rubyforge.org

Ezra Z. wrote:

Rolando-

Don’t do that :wink: You will only run into problems trying to use
threads that way within your rails applications. While some of the
parts of rails are sort of thread safe, the entire environment as a
whole is not thread safe. So you will get the errors that you are
currently getting. I wrote the BackgrounDRb[1] plugin for just this
type of problem. You can put the long tasks in another process in a
drb server and get status updates from within rails. Have a look and
see what you think.

Cheers-
-Ezra

[1] http://backgroundrb.rubyforge.org

Thanks!
your plugin seems to be just what I needs. I’ll give it a try.

regards,
rolando.-

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs