How can I change the connection of one thread? I want do that:
# slow query process at background
Thread.new do
100000.times { User.first.update_attributes(some_field: (rand * 100).to_i)
}
end
# more slow query process
100000.times { User.first.update_attributes(some_field_2: (rand * 100).to_i)
}
I want that these 2 threads runs asynchronously but I discover that Rails
uses one single connection to do this. I had tried the below too, but
although Rails create a new connection, the "User" don't use it:
# slow query process at background
Thread.new do
conn = ActiveRecord::Base.connection_pool.checkout()
100000.times { User.first.update_attributes(some_field: (rand * 100).to_i)
}
ActiveRecord::Base.connection_pool.checkin(conn)
end
I had tried to set "ActiveRecord::Base.connection = conn" but didn't work
too.
It is possible to each thread have your own connection? How can I set the
thread connection?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.