Created
September 4, 2013 12:21
-
-
Save leifcr/6436217 to your computer and use it in GitHub Desktop.
Async mailing with Devise, DelayedJob and devise-async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'devise/async' | |
require 'devise/async/backend/base' | |
require 'devise/async/backend/delayed_job' | |
if defined?(Devise::Async::Backend::Base) && defined?(Devise::Async::Backend::DelayedJob) | |
module Devise | |
module Async | |
module Backend | |
class Base | |
def perform_with_locale(method, resource_class, resource_id, opts, locale) | |
resource = resource_class.constantize.to_adapter.get!(resource_id) | |
opts.symbolize_keys! | |
I18n.with_locale(locale) do | |
mailer_class.send(method, resource, opts).deliver | |
end | |
end | |
end | |
class DelayedJob < Base | |
def self.enqueue(*args) | |
new.delay(:queue => Devise::Async.queue).perform_with_locale(*args + [I18n.locale]) | |
end | |
end | |
end | |
end | |
end | |
else | |
raise "Cannot initialize Devise Async backend properly! Critical!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment