So, I'm using sharding to provide multi-tenancy to my application with each
customer getting their own database and a shared api pool that will listen
to a message queue to add connections to the pool as new customers signup
to prevent restarting the api servers. In my api, I do something like this:
# connection initialization
servers = {}
# connect to configuration db and read tenant configs
TENANT_DB = Sequel.connect(host: ...)
TENANT_DB[:tenants_configs].each { |config| servers[config[:subdomain]] = {
host: ... } }
TENANT_DB.disconnect
DB = Sequel.connect( { host: ... }, servers: servers, logger: logger )
# around_action
DB.with_server(subdomain.to_sym) do
yield
end
# message consumer
DB.add_server(host: ..., database: ..., user: ..., password: ...)
If the server was passed in during initialization, it works as expected,
but using newly added server, the queries inside the with_server block are
running against the default server. I was looking at using the arbitrary
server extension as an alternative to what I'm encountering, but didn't
like the thought of maintaining a global variable for all the "missing"
configurations and not sure of potential performance issues using that
approach. I'm not sure if I overlooked something or just not doing
something incorrectly.
Thanks
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.