brandonhilkert / sucker_punch

Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
MIT License
2.65k stars 114 forks source link

resque mailer or rails mailer to sucker_punch mailer #170

Closed dashbitla closed 8 years ago

dashbitla commented 8 years ago

On Rails 3.2!

What is the best way to use sucker_punch for emailing? How do we define methods and how do we call it when we have multiple mail methods in the Mailer class?

Our Mailer Class has about 100+ different email methods such as:

ETicketMailer.new_coupon_code(searchbus, coupon_id).deliver
ETicketMailer.cancel_tickets(ticket_ids, coupon_id).deliver
ETicketMailer.request_seat(o_request_id).deliver

How to convert this to sucker_punch? Whats the easiest way?

It doesn't make sense to create separate Job class for each mail method!

Whats the best way to use sucker_punch for mailers?

brandonhilkert commented 8 years ago
class EmailWorker
  include SuckerPunch::Job

  def perform(klass, name, *args)
    klass.constantize.send(name.to_sym, *args).deliver
  end
end

and use:

EmailWorker.perform_async(ETicketMailer, :new_coupon_code, searchbus, coupon_id)
EmailWorker.perform_async(ETicketMailer, :cancel_tickets, ticket_ids, coupon_id)
EmailWorker.perform_async(ETicketMailer, :request_seat, o_request_id)