I'm working on a Rails app that needs to execute some code when it boots. Since I want to share this behavior with future apps, I have put this code into a gem using a Railtie class.
lib/my_gem/railtie.rb
module MyGem
class Railtie < Rails::Railtie
initializer 'my_gem.registration' do
# the code goes here
end
end
end
In this way, the initializer is executed by each worker (I'm using Pow in development with the 2 default workers and I guess it will be the same in production with unicorn and multiple workers) and this messes up the entire app (in the initializer I set an ENV variable and this is overwritten by each worker).
Is there a way to make the code be executed only by the 1 (the first) worker ???
Thanks for your help and have a nice day.