Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to preserve all connection pools #16

Closed
woahdae opened this issue Nov 17, 2010 · 2 comments
Closed

Need to preserve all connection pools #16

woahdae opened this issue Nov 17, 2010 · 2 comments
Assignees

Comments

@woahdae
Copy link

woahdae commented Nov 17, 2010

Rails supports multiple databases among models via Model.establish_connection('other_database'), and spawn resets these connection pools:

Ex, we put delayed jobs in a different database:

ActiveRecord::Base.connection_handler.connection_pools.keys # => [ "Delayed::Job", "ActiveRecord::Base"]

spawn { ActiveRecord::Base.connection_handler.connection_pools.keys } # => ["ActiveRecord::Base"]

I'm currently hacking around this, but thought I'd make a ticket.

@woahdae
Copy link
Author

woahdae commented Dec 6, 2010

I've done more hacking, and thought I'd share. Still don't feel like patching spawn's code, it does a lot of connection management already that I don't want to mess with, but I'm using DelayedJobSpawner and put this in its prefork:

$AR_connection_pools = ActiveRecord::Base.connection_handler.connection_pools.map do |name, pool|
  OpenStruct.new(:model => name, :config => pool.spec.config)
end

and this in the each_spawn:

$AR_connection_pools.each {|c| c.model.constantize.establish_connection(c.config)}

maybe that will help push the ticket along.

BTW, rails 2.3.5

@ghost ghost assigned tra Aug 22, 2011
@mnoack
Copy link
Collaborator

mnoack commented Jul 6, 2014

Closing to clean up as this in an old issue, if this is still valid on the latest version of spawnling then please re-open the issue and I will address it.

@mnoack mnoack closed this as completed Jul 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants