Skip to content
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

prepare DSL block called multiple times #112

Open
trafium opened this issue Jul 1, 2021 · 2 comments
Open

prepare DSL block called multiple times #112

trafium opened this issue Jul 1, 2021 · 2 comments
Assignees

Comments

@trafium
Copy link

trafium commented Jul 1, 2021

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
@jodosha jodosha self-assigned this Jul 1, 2021
@jodosha
Copy link
Member

jodosha commented Jul 1, 2021

@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?

@trafium
Copy link
Author

trafium commented Jul 1, 2021

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants