You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if there is a better, recommended way of handling this situation? Maybe a way to configure (or wrap) the default thread execution? Or if I could easily write a new in_db_threads helper that would behave like in_threads, but wrap with activerecord, but that seems impossible without monkey patching this gem.
The text was updated successfully, but these errors were encountered:
Currently library doesn't have any supported way to hook into the process.
The workaround looks fine, only problem it being a monkey patch if/when something changes.
I checked introducing another wrapper (.in_threads.with_progress('users').with_db.), but looks like it will not be simple, so best way would be to introduce hooks like .in_threads(around_each: proc{ |&block| ….with_connection(&block) }) and then you could add a method like in_db_threads to wrap it.
If comes a stage when I need to get rid of the patch, I'll happily try implementing that hook idea.
I'll let you decide if you want to keep this issue open to track the idea.
a ruthlessly handy library thank you,
I make use of it to speed up generating database seeds in a rails app (
db/seeds.rb
) file.as such:
In order to make use of database connections across threads, one needs to wrap each block with
ActiveRecord::Base.connection_pool.with_connection
.For readability concerns, I would like to avoid sprinkling
ActiveRecord::Base.connection_pool.with_connection
throughout my seeds file.Right now I use the following heavy handed global workaround:
I was wondering if there is a better, recommended way of handling this situation? Maybe a way to configure (or wrap) the default thread execution? Or if I could easily write a new
in_db_threads
helper that would behave likein_threads
, but wrap with activerecord, but that seems impossible without monkey patching this gem.The text was updated successfully, but these errors were encountered: