Pergunta

My application was sending mails in background in development but recently i installed redis and resque to use resque along with resque-mailer and now nothing is working.Everytime i get a message RuntimeError Invalid delivery method :resque.I have been trying hard to figure out whats wrong because earlier i just included resque-mailer in user_mailer.rb and thats it,my mails were running but now i dont know what wrong i did.below are my relevant file AFTER INSTALLING REDIS using Railscasts for resque.I googled alot to find but many times i came across monkey patching devise but i dont think i need to do that as my mailers were working fine without worrying about devise.Using ruby 1.9.3 and rails 3.2 im getting same error when tried with sidekiq :(

my gemfile.

gem 'resque','1.19.0' ,:require => "resque/server"
gem 'resque_mailer'

my user_mailer.rb

class UserMailer < ActionMailer::Base
  include Resque::Mailer
  default from: "support@mywebsite.com"


def logged_in(user.id)
  Rails.logger.info 'sending mail----------registeration mail----------'
  @user=User.find(user_id)
  p @user
  ###line number 19 is below
  mail(:to => @user.email, :subject => " Hi #{@user.username},You logged-in just now ")
end

app/controllers/users/devise/sessions_controller.rb

##enqueue the mailer using resque and send mail asynchronously
###this was working earlier but now its not so i made use of railscasts above to use redis
###UserMailer.logged_in(resource.id).deliver
@user_id=resource.id
Resque.enqueue(UserMailerWorker,@user_id)

now the changes that i did using Railscasts and mail is not sending giving above error

my worker

class UserMailerWorker
  @queue = :user_mailer_job_queue
  def self.perform(user_id)
    p 'usermailer worker sending logged in mail----'
    p user_id
    UserMailer.logged_in(user_id).deliver
  end
end

backtrace error as seen in resque-web UI---

     localhost.localdomain:8119 on mailer at just now
    Retry or Remove
Class
    UserMailer
Arguments

    "logged_in"
    7

Exception
    RuntimeError
Error
    Invalid delivery method :resque

    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/delivery_methods.rb:71:in `wrap_delivery_behavior'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/delivery_methods.rb:83:in `wrap_delivery_behavior!'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:628:in `mail'
    /mnt/hgfs/latest-master/latest/app/mailers/user_mailer.rb:19:in `logged_in'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionpack-3.2.0/lib/abstract_controller/base.rb:167:in `process_action'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionpack-3.2.0/lib/abstract_controller/base.rb:121:in `process'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionpack-3.2.0/lib/abstract_controller/rendering.rb:45:in `process'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:456:in `process'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:451:in `initialize'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `new'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `perform'
Foi útil?

Solução

well after removing and resetting my application...i came to know why i was getting this error.its because i was not starting the resque job as well as redis.so after starting redis using redis-server and resque using bundle exec rake resque:work QUEUE='*'...my asynchronous mail started working without any problem just by including include Resque::Mailer

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top