I have an initializer in my config directory, which is something like this:
ActiveSupport::Notifications.subscribe "handle_translation_event" do |name, start, finish, id, payload|
puts "Called"
end
I have a Rails development server running ( rails s ), and I start in parallel a rails console ( rails c ). Imagine that in the rails console, I write:
ActiveSupport::Notifications.instrument("handle_translation_event")
I cannot see this reflected in the server logs. Is it possible to trigger an event from the console, and have it affect the server? My guess is no.
ActiveSupport::NotificationsusesActiveSupport::Notifications::Fanoutclass as notifier to notify the subscribers.This notifier uses simple instance variables to store the subscribers.
You can create your own implementation (with a database backed solution) and you can set the actual notifier to your implementation by setting the
notifierattribute ofActiveSupport::Notifications.I could imagine a simple Redis backed implementation of it, because it has a publish/subscribe feature. But if you don’t have Redis as a dependency, you can also do it in SQL.