reactor
reactor copied to clipboard
introduce ActionMailer mixin
The theory is tested in production and quite sound, we just need to add this to reactor.
class MyMailer < ActionMailer::Base
include Reactor::EventMailer
on_event :user_created do |event|
user = event.actor
mail to: user.email, subject: "Welcome to the app!"
end
end
It works as you'd expect, simply extending the functionality of a typical ActionMailer method such that it is also automatically run in a sidekiq job on that event name.
This issue has been sitting for awhile. Can this code be extracted and shared? How different is it from Subscribable
?
Looking the current mailer worker code, I am not entirely sure how that is supposed to be used? The specs make it look like you need to create a worker per email, which doesn't seem right to me.
That said, the regular subscriber mixin looks to work if you change the class_exec to be an instance_exec like this:
mailer.run_callbacks(:process_action) do
if action.is_a?(Symbol)
mailer.public_send(action, event)
else
mailer.instance_exec(event, &action)
end
end
Then all the binding for the view like @user = event.actor
bind correctly. I still need to run an integration test to make sure the emails get out the door, but all my specs are working.