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
We have 2 servers: master and a slave server. slave server is primarily being used to handle reports. All the long background running processes are pushed to the slave server. We are using sidekiq for background processing.
Now, whenever a report is ready we create a Download object in which the generated report is attached. As the process is running in slave we need to connect to master in order to create Download object. Code looks something like this:
def perform(tenant_name)
Apartment::Tenant.switch(tenant_name) do
# data processing code here....
connection = MasterDbConnectionService.connect(tenant_name)
Download.create!(time_taken: time_taken, file: file) # Pseudo code
# Disconnect from the previously established connection
MasterDbConnectionService.disconnect(connection)
end
end
But we are intermittently facing the error especially for long running jobs most probably because of sidekiq retrying that job.
ActiveRecord::ConnectionNotEstablished) "No connection pool with 'primary' found.
MasterDbConnectionService code:
def connect(tenant_name)
ActiveRecord::Base.establish_connection(master_config.merge(schema_search_path: "'#{tenant_name}',public,shared_extensions"))
end
def disconnect(connection)
ActiveRecord::Base.remove_connection(connection)
end
I was trying to replace https://github.com/sobrinho/activerecord-connections to Apartment because the other gem is too old and does not deal well with too many databases (it does not closes the connections properly)
We have 2 servers: master and a slave server. slave server is primarily being used to handle reports. All the long background running processes are pushed to the slave server. We are using sidekiq for background processing.
Now, whenever a report is ready we create a Download object in which the generated report is attached. As the process is running in slave we need to connect to master in order to create Download object. Code looks something like this:
But we are intermittently facing the error especially for long running jobs most probably because of sidekiq retrying that job.
MasterDbConnectionService code:
Config: Nginx, Phusion Passenger, Postgres, ruby-2.3.1, rails 5.1.3
Full stack trace:
The text was updated successfully, but these errors were encountered: