Using multiple clients, before execute callbacks are shared between clients
Closed this issue · 1 comments
JanStevens commented
Hello,
When using multiple clients I noticed that the before execute callbacks are shared between artemis instances, following script shows the problem
require 'bundler/inline'
gemfile do
gem 'artemis'
gem 'awesome_print'
end
require 'artemis'
require 'ap'
class ClientA < Artemis::Client
before_execute do |_, _, _, _|
puts 'CLIENT A BEFORE EXECUTE'
end
end
class ClientB < Artemis::Client
before_execute do |_, _, _, _|
puts 'CLIENT B BEFORE EXECUTE'
end
end
ap ClientA.before_execute
I expect that ClientA.before_execute
returns an Array of 2 element (where last element is nil) instead I get back an array of 3 procs. another slimmed down version that shows that in this case ActiveSupport::Configurable
is not the solution you would want to use.
class ConfigurableTest
include ActiveSupport::Configurable
config.before_callbacks = []
class << self
def before_execute(test)
config.before_callbacks << test
end
end
end
class TestA < ConfigurableTest
before_execute "a"
end
class TestB < ConfigurableTest
before_execute "b"
end
ap TestA.config.before_callbacks
ap TestB.config.before_callbacks
ap ConfigurableTest.config.before_callbacks
I think it's best to move away from ActiveSupport::Configurable
and just use regular class methods and variables
yuki24 commented
Thanks for reporting. Yes, this is definitely unexpected and I'd expect the same as you described above.