DEV Community

Discussion on: TIL: Using Different Database Connection with ActiveRecord Transactions

Collapse
 
ericparshall profile image
Eric Parshall • Edited

Maybe you are using Rails 4, because in Rails 5 this method just locked my whole rails server. It seems the new way is to use the ThreadPoolExecutor as described in Wrapping Application Code

Just thought I'd share this with those that had the same problem I did. I was trying to cache an API response inside of an ActiveRecord validation method. Now I do it like this:

Thread.new do
  Rails.application.executor.wrap do
     model.save
  end
end
Collapse
 
amrrbakry profile image
Amr El-Bakry

Yes, I was using Rails 4. Thank you for sharing this, Eric!