`prepare` DSL block called multiple times
In the context of Hanami app:
Let's say we have my_app/config/environment.rb configured like this:
module Foo
def self.included(klass)
puts 'Foo was included'
end
end
Hanami.configure do
mount Web::Application, at: '/'
mailer do
root 'lib/my_app/mailers'
delivery :test
prepare do
include Foo
end
end
end
And I have a single mailer class in project. Then it properly calls prepare block once for mailers indicated by output:
Foo was included
But if I want to add additional configuration for some environment, as soon as I specify another mailer block, everything in my initial prepare block gets called another time on app initialisation:
Hanami.configure do
mount Web::Application, at: '/'
mailer do
root 'lib/my_app/mailers'
delivery :test
prepare do
include Foo
end
end
environment :development do
mailer do
# Nothing here
end
end
end
Foo was included
Foo was included
@trafium Could you please tell me more about your context? How do you start your app? Do you use code reloading? Does this happen in production mode? How do you start your app in production mode? Do you use web server clustering?
@jodosha
https://github.com/trafium/hanami-mailer-prepare-double-call-bug
Here, I made an example app. My personal project uses hanami-reloader and it is not yet deployed to production, this example repo uses default shotgun, it's reproducible with either. Multiple inclusion can be seen when running
bundle exec hanami console
or
bundle exec hanami server (in example app you can see Foo is included printed twice on each request).
On startup in production mode (DATABASE_URL="sqlite://db/test_app_development.sqlite" SMTP_PORT="" SMTP_HOST="" HANAMI_ENV=production bundle exec hanami c) the behaviour is the same.