reactor icon indicating copy to clipboard operation
reactor copied to clipboard

introduce ActionMailer mixin

Open winfred opened this issue 10 years ago • 2 comments

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.

winfred avatar Jun 15 '14 21:06 winfred

This issue has been sitting for awhile. Can this code be extracted and shared? How different is it from Subscribable?

sirwolfgang avatar Mar 14 '18 17:03 sirwolfgang

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.

sirwolfgang avatar Apr 30 '18 22:04 sirwolfgang