Sha256: fb624e0e57ed139443656a1845f477860d8bfeb304f4676eb5e30092d22bd641

Contents?: true

Size: 886 Bytes

Versions: 12

Compression:

Stored size: 886 Bytes

Contents

require 'sidekiq/extensions/generic_proxy'

module Sidekiq
  module Extensions
    ##
    # Adds 'delay' and 'delay_for' 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)
    class DelayedMailer
      include Sidekiq::Worker
      # I think it's reasonable to assume that emails should take less
      # than 30 seconds to send.
      sidekiq_options :timeout => 30

      def perform(yml)
        (target, method_name, args) = YAML.load(yml)
        target.send(method_name, *args).deliver
      end
    end

    module ActionMailer
      def delay
        Proxy.new(DelayedMailer, self)
      end
      def delay_for(interval)
        Proxy.new(DelayedMailer, self, Time.now.to_f + interval.to_f)
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
sidekiq-2.3.3 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.3.2 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.3.1 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.3.0 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.2.1 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.2.0 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.1.1 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.1.0 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.0.3 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.0.2 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.0.1 lib/sidekiq/extensions/action_mailer.rb
sidekiq-2.0.0 lib/sidekiq/extensions/action_mailer.rb