We have a Sidekiq background job that is really slow and db intensive, so we want to configure it to read from our Postgres follower database instead of the standard one.
To do this I wrote a small utility class that connects an ActiveRecord model to the follower db if it is not already connected.
Assume connected to follower if not connected to default connection db
klass.connection_config[:database] != ActiveRecord::Base.connection_config[:database]
In the Sidekiq background job we use it like this:
SomeARClass.where(:some_id => id).some_scope(…)
Is this a good solution or does anyone have other suggestions for how to solve this?
We tried the Octopus gem but ran into a bug (https://github.com/tchandy/octopus/issues/280) with it.
We also have another background job that we would like to switch over to use the follower database but for another ActiveRecord model, is there some way to share the already established connection for another ActiveRecord class?
Any other feedback on this approach?