DEV Community

Discussion on: How to implement Pub/Sub pattern in Ruby on Rails?

Collapse
 
mrnagoo profile image
Anag

So in here...

class EmailSubscription

  def on_animal_created(event)
    puts "Email will be sent #{event[:payload]}"
   #send email logic for animal creation
  end

end
Enter fullscreen mode Exit fullscreen mode

You would actually send an email or call the service that sends emails.
or no?

Collapse
 
vladhilko profile image
Vlad Hilko

My approach would be to delegate the email sending task to a separate job or use something like this:

AnimalMailer.with(user: event[:user]).welcome_email.deliver_later
Enter fullscreen mode Exit fullscreen mode

That way, the service can continue working without waiting for the send to complete.

Collapse
 
mrnagoo profile image
Anag

cool, thanks. Good write up!