-
-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Configuration#multi_tenant!
for opting into multi-tentant support where configuration is per-thread
#556
Conversation
95c6aa6
to
603ac93
Compare
Thank you for the great contribution! Left some comments. |
603ac93
to
010226b
Compare
Thanks for the feedback, took that into account. I followed the same pattern with attributes to apply to the caches that were changed in #549. Also documented the configuration in the README. I'm still unsure of whether |
I think this is the right framing of the problem. My thought is That is a bit weird, but having it effected by Wdyt? |
010226b
to
f2edb61
Compare
I tweaked things so The test gets a little wonky as we have to use It slightly irks me that Ultimately I'd really like feedback from someone with a multi-tenant setup, as my experience is only with single-tenant setups, so I'm just speculating on how a multi-tenant setup might look. My motivation with this PR was to address that #549 broke my single-tenant set up. |
f2edb61
to
dbb733c
Compare
…rt where configuration/caching is per-thread This is a follow up to NetSweet#549 to improve usage in a single tenant scenario where you might configure NetSuite on the main thread (ie. via Rails initializer), then make requests in another thread (ie. Sidekiq jobs). By default we assume single-tenant usage and the configuration/cache is shared across all threads. If you opt into multi-tenant usage, each child thread starts with it's own empty configuration/cache that is not shared to other threads.
dbb733c
to
968e3c8
Compare
@cgunther Awesome work! I have a multi-tenant setup. Going to merge this in and run it against our internal test suite. |
Thanks for the merge. Things seem to work well for my single-tenant setup. Assuming they work well for your multi-tenant setup, it might be wise to release a new version. I suspect the current version (v0.9.0) would be broken for anyone with a single-tenant setup, but using threads (ie. puma, sidekiq) and configuring outside those child threads as a result of #549. |
@cgunther definitely! I'll get a release out soon :) |
This is a follow up to #549 to improve usage in a single tenant scenario where you might configure NetSuite on the main thread (ie. via Rails initializer), then make requests in another thread (ie. Sidekiq jobs).
By default we assume single-tenant usage and the configuration is shared across all threads. If you opt into multi-tenant usage, each child thread starts with the main thread's configuration, but can then be further configured without altering other threads.
Rather than mixing
Thread.current
and global instance variables, I'm usingThread.main
for the global configuration.Child threads start with a copy of the main thread's attributes, figuring this still allows you to set some things globally on the main thread (ie. timeouts), then per-tenant things on the child threads (ie. account).
Whether we're multi-tentant or not is always stored on the main thread, not as an attribute, as we want/need that to be global.
One possible concern is what happens if you set some configuration before calling
multi_tenant!
, particularly when called from a child thread. Whatever configuration you set beforemulti_tenant!
would be stored on the main thread (thinking we're single-tenant), not the child thread, which could be surprising. Maybe we need a safety check so it'll error if you callmulti_tenant!
after attributes have already been set, forcing you to specifymulti_tentant!
first?reset!
also resets whether it's multi-tenant, taking the stance that it's a full reset, not just resetting the thread.I didn't touch caches yet, wanted to make sure we're on the right path first. I'll need to mention this in the README too.