Coder Social home page Coder Social logo

Comments (8)

sobrinho avatar sobrinho commented on August 19, 2024 1

I think the same approach of #55 will work for unicorn:

before_fork do |server, worker|
  ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each do |shard, connection_pool|
    connection_pool.disconnect!
  end
end

But I tested on unicorn 4.4.0 and it worked fine without defining any hook.

Maybe it's not necessary anymore or something on octopus master fixed that.

Closing :)

from octopus.

damhonglinh avatar damhonglinh commented on August 19, 2024 1

I think solution from here #319 (comment) is more refreshed.

from octopus.

alxgsv avatar alxgsv commented on August 19, 2024

Here is my after_fork:

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

Maybe it is incorrect to reconnect to db with octopus in this way?

from octopus.

alxgsv avatar alxgsv commented on August 19, 2024

In another words my question is:

How to correctly disconnect and connect to database when using octopus?

Thanks.

from octopus.

alxgsv avatar alxgsv commented on August 19, 2024

This workaround helped me:

after_fork do |server, worker|
    Octopus.config["production"]["master"] = ActiveRecord::Base.connection.config
    ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end

How correct is it? (In case that I use unicorn only in production)

from octopus.

thiagopradi avatar thiagopradi commented on August 19, 2024

Maybe you need to initialize all shards before running, try to use this fix:

after_fork do |server, worker|
ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each {|k,v| v.clear_reloadable_connections! }
end

from octopus.

thiagopradi avatar thiagopradi commented on August 19, 2024

of course, shards not using capital letter

from octopus.

brlo avatar brlo commented on August 19, 2024

Refresh solution:

unicorn.rb:

before_fork do |server, worker|
  # the following is highly recommended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    ActiveRecord::Base.connection_proxy.shards.each { |s,pool| pool.disconnect! }
  end
end

after_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection_proxy.shards.each do |s,pool|
      pool.clear_reloadable_connections!
    end
  end
end

from octopus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.