Class: Sidekiq::Extensions::DelayedMailer

Inherits:
Object
  • Object
show all
Includes:
Worker
Defined in:
lib/sidekiq/extensions/action_mailer.rb

Overview

Adds 'delay', 'delay_for' and `delay_until` methods to ActionMailer to offload arbitrary email delivery to Sidekiq. Example:

UserMailer.delay.send_welcome_email(new_user)
UserMailer.delay_for(5.days).send_welcome_email(new_user)
UserMailer.delay_until(5.days.from_now).send_welcome_email(new_user)

Instance Attribute Summary

Attributes included from Worker

#jid

Instance Method Summary collapse

Methods included from Worker

clear_all, drain_all, included, jobs, #logger

Instance Method Details

#perform(yml) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/sidekiq/extensions/action_mailer.rb', line 15

def perform(yml)
  (target, method_name, args) = YAML.load(yml)
  msg = target.__send__(method_name, *args)
  # The email method can return nil, which causes ActionMailer to return
  # an undeliverable empty message.
  msg.deliver if msg && (msg.to || msg.cc || msg.bcc) && msg.from
end