created an initializer like so as recommended in the documentation:
ActiveSupport.on_load(:active_event_store) do |store|
# Subscribed event handlers to events here
end
What did you expect to happen?
That it would work as expected and the subscriber would only be called once.
What actually happened?
The subscriber would only be called once, until a file changed and code was reloaded, resulting in the on_load being called again, and if the event was fired, the subscriber would be called twice. For further clarification, the initializer file is only called once on app boot, but the block passed to ActiveSupport.on_load(:active_event_store) is called every time code reload happens.
Additional context
Changing the initializer to:
ActiveSupport.on_load(:active_event_store, { run_once: true }) do |store|
# Subscribed event handlers to events here
end
worked like a charm. Either, my app has some funky config, or this is a bug in this libraries documentation. I suggest that the documentation is updated to recommend creating the initializer with :run_once, unless the application I am working on is doing something dumb. Happy to submit a PR with the README change, unless this shouldn't be happening in standard rails applications.
What did you do?
created an initializer like so as recommended in the documentation:
What did you expect to happen?
That it would work as expected and the subscriber would only be called once.
What actually happened?
The subscriber would only be called once, until a file changed and code was reloaded, resulting in the on_load being called again, and if the event was fired, the subscriber would be called twice. For further clarification, the initializer file is only called once on app boot, but the block passed to
ActiveSupport.on_load(:active_event_store)
is called every time code reload happens.Additional context
Changing the initializer to:
worked like a charm. Either, my app has some funky config, or this is a bug in this libraries documentation. I suggest that the documentation is updated to recommend creating the initializer with
:run_once
, unless the application I am working on is doing something dumb. Happy to submit a PR with the README change, unless this shouldn't be happening in standard rails applications.