instacart / makara

A Read-Write Proxy for Connections; Also provides an ActiveRecord adapter.
http://tech.taskrabbit.com/
MIT License
930 stars 170 forks source link

[Question] Force connection to master #251

Open AaronBaldwin opened 4 years ago

AaronBaldwin commented 4 years ago
def handle_request_after_third_party_record_creation
  CreatedResourceClass.connection.stick_to_master!
  CreatedResourceClass.find(params[:id]) # will go to master
end

Is there a way to force all connections to use master rather than specifying one specific resource? I have a service which I need to contact another service and it should always use master in this case. I can probably add some middleware to my application to detect if the incoming request is from the 2nd service and force use to master. However, its not practical to add that in to every endpoint and every possible resource that may need fetching.

Is it possible to tell one connection to always use master for every resource?

AaronBaldwin commented 4 years ago

As a sidenote, Object.connection seems to be the same for all my Objects when I do a local test. They al hard equal each other. On my local environment I only have one database and this is using a debugger rather than the normal execution, so not sure if that is expected to also be true for production environment.