Giter Site home page Giter Site logo

Comments (10)

caseyprovost avatar caseyprovost commented on August 23, 2024 1

We use Unicorn and a failure standard configuration I think, which I shared below. I am sure it is just a MonkeyPatch I am missing or something.

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: *****
  password: *****
  host: 127.0.0.1
  port: 3306

development:
  <<: *default
  database: chewy_development

development_slave:
  <<: *default
  database: chewy_development_secondary

What is the downside of doing something like this instead?

class ReportObject < ApplicationRecord
  self.table_name = 'some_table'
  establish_connection(:development_slave)
end

ReportObject.connection.exec('SELECT COUNT(*) FROM some_table')

or

def on_slave(&block)
  databases = YAML.load(File.read('config/database.yml'))
  connection = ActiveRecord::Base.establish_connection(databases["#{Rails.env}_slave"])
  result = yield
  connection.disconnect!
  result
end

from standby.

kenn avatar kenn commented on August 23, 2024

cc @asanghi any insights? I haven't gotten around to upgrading yet.

from standby.

caseyprovost avatar caseyprovost commented on August 23, 2024

It might also be be good to have documentation around using raw SQL if it doesn't work like this:

result = Slavery.on_slave{ ActiveRecord::Base.connection.execute('SELECT * FROM users') }

from standby.

asanghi avatar asanghi commented on August 23, 2024

We have this in production and see no problems. I can investigate though. @caseyprovost can you post your database.yml? Your original example is pretty standard and should work.

from standby.

kenn avatar kenn commented on August 23, 2024

The only case I can think of is that you are running a slave query from multiple threads at the same time, creating a race condition initializing Slavery.slave_connections.

Do you have something related? (e.g. config/initializers, before|after_fork in config/puma.rb, etc.)

from standby.

kenn avatar kenn commented on August 23, 2024

What is the downside of doing something like this instead?

You can do whatever you want, but this is an issue for the Slavery gem and don't treat us like your free consultant.

If necessary, reopen with answer to my questions please.

from standby.

caseyprovost avatar caseyprovost commented on August 23, 2024

@kenn I did answer the things asked for including posting my database.yml and sharing we are using unicorn and not Puma. I also cannot find any other evidence of forking.

I was also not attempting to be unfair or abuse your time, as an OS contributor myself I try to be aware and protective of that. My question was more accurately what is the advantage of Slavery to the approaches I mentioned? I am honestly curious.

Hopefully this was helpful.

from standby.

kenn avatar kenn commented on August 23, 2024

You said

I am sure it is just a MonkeyPatch I am missing or something.

but didn't post that.

The other question is unrelated to the original problem and should go to a separate issue. To me the former looks ok but the latter is horrible - too much overhead. And by removing the overhead you'll basically end up creating the same thing as this gem. Remember, what this gem does is VERY MINIMAL.

from standby.

caseyprovost avatar caseyprovost commented on August 23, 2024

For the record the problem is the ActiveUUID gem. This library and that result in an infinite recursive loop.

from standby.

kenn avatar kenn commented on August 23, 2024

I just installed activeuuid but it doesn't happen. Would appreciate if you can make a repro with a fresh new Rails setup.

from standby.

Related Issues (13)

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.