Class: Sidekiq::Extensions::DelayedMailer

Inherits:
Object
  • Object
show all
Extended by:
TestingExtensions
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 TestingExtensions

jobs_for

Methods included from Worker

clear_all, drain_all, included, jobs, #logger

Instance Method Details

#perform(yml) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sidekiq/extensions/action_mailer.rb', line 17

def perform(yml)
  (target, method_name, args) = YAML.load(yml)
  msg = target.public_send(method_name, *args)
  # The email method can return nil, which causes ActionMailer to return
  # an undeliverable empty message.
  if msg
    msg.deliver_now
  else
    raise "#{target.name}##{method_name} returned an undeliverable mail object"
  end
end