Skip to content

Instantly share code, notes, and snippets.

@leifcr
Created September 4, 2013 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leifcr/6436217 to your computer and use it in GitHub Desktop.
Save leifcr/6436217 to your computer and use it in GitHub Desktop.
Async mailing with Devise, DelayedJob and devise-async
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