just to let you know, I had to monkeypatch the MangoPay module so that configurations are thread-local. I did this in order to achieve multi-tenancy of MangoPay accounts in a multithreaded server (puma). Each time I receive a new request I configure MangoPay accordingly. Since each configuration lives in its own thread, I'm guaranteed each request wont mistakingly use the configuration of another request, which is the case if MangoPay.configuration is a class variable (it is shared among all threads).
Here is the patch in question
MangoPay.class_eval do
def self.configuration=(value)
Thread.current[:mangopay_configuration] = value
end
def self.configuration
Thread.current[:mangopay_configuration]
end
def self.configure
config = self.configuration || MangoPay::Configuration.new
yield config
self.configuration = config
end
end
Hey @TristeFigure, thanks very much for this detailed report. Do you think you could do a pull request with the optim to be sure I've totally understood your suggestion?
Hi,
just to let you know, I had to monkeypatch the
MangoPay
module so that configurations are thread-local. I did this in order to achieve multi-tenancy of MangoPay accounts in a multithreaded server (puma). Each time I receive a new request I configure MangoPay accordingly. Since each configuration lives in its own thread, I'm guaranteed each request wont mistakingly use the configuration of another request, which is the case if MangoPay.configuration is a class variable (it is shared among all threads). Here is the patch in questionCheers