Delayed_job:任何调用上的未定义方法错误

时间:2011-09-06 08:09:01

标签: ruby-on-rails actionmailer delayed-job

我有一个rails 3.0.5应用程序,与delayed_job 2.1.4一起正常工作。

自从我触摸应用程序已经有几周了,但我只是去调整它并注意到delayed_job被破坏了。具体来说,对delayed_job的任何调用都会在延迟后返回方法上的“未定义方法”错误。 (例如,StudentMailer.delay.student_mail('test')在“student_mail”上返回“未定义的方法”)我无法弄清楚原因。一些事情:

  • 使用StudentMailer.student_mail('test')替换StudentMailer.delay.student_mail('test')。deliver可以很好地发送邮件。

  • 网站上没有更改任何宝石版本,自开发以来一直被锁定

  • 已卸载RVM&重新安装

  • 发生所有邮件程序

代码&错误如下:

MAILER:

class StudentMailer < ActionMailer::Base
  def course_signup(email, password, course, enrolment)
    @email = email
    @password = password
    @course = course
    @enrolment = enrolment
    @student = Student.where(:email => email).first
    if (@student.user.first_name && @enrolment.student.user.last_name) then
      @username = @student.first_name.gsub(/[^[:alnum:]]/, '').downcase + '.' + @student.last_name.gsub(/[^[:alnum:]]/, '').downcase
    else
      @username = "fcuser#{@student.id}"
    end
    mail(:to => email, :from => ENV['ACCOUNTS_EMAIL'], :subject => "You have been enrolled as a student for #{course}", :content_type => 'text/plain') 
  end
end

MODEL(梅勒呼吁after_save)

  after_create {
    studentmailer = StudentMailer
    #studentmailer.course_signup(self.student.email, self.purchase.course).deliver
    randompass = RandomPassword.random_string(20)
    randomGatewayPass = RandomPassword.random_string(8)
    studentmailer.delay.course_signup(self.student.email, randomGatewayPass, self.purchase.course, self)
    self.save   }

CONFIG /的boot.rb

require 'yaml'
YAML::ENGINE.yamler = 'syck'

require 'rubygems'
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
  ENV['BUNDLE_GEMFILE'] = gemfile
  require 'bundler'
  Bundler.setup
rescue Bundler::GemNotFound => e
  STDERR.puts e.message
  STDERR.puts "Try running `bundle install`."
  exit!
end if File.exist?(gemfile)

DELAYED JOB ERROR:

  

{undefined method course_signup' for #<Class:0x007fbcf61850c8> /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/performable_mailer.rb:6:in perform'\ n / Users / john / .rvm / gems / ruby​​-1.9.2-p290 / gems / delayed_job-2.1.4 / lib / delayed / backend / base.rb :87:在   invoke_job'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in 阻止(2级)   运行'\ N /用户/约翰/ .rvm /红宝石/红宝石1.9.2-P290 / LIB /红宝石/ 1.9.1 / timeout.rb:58:在   timeout'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in 阻止   运行'\ N /用户/约翰/ .rvm /红宝石/红宝石1.9.2-P290 / LIB /红宝石/ 1.9.1 / benchmark.rb:310:在   realtime'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:119:in 运行'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ worker.rb:177:在   reserve_and_run_one_job'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:104:in 阻止   work_off'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ worker.rb:103:在   times'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:103:in work_off'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ worker.rb:78:在   block (2 levels) in start'\n/Users/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in 实时'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ worker.rb:77:在   block in start'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:74:in 环'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ worker.rb:74:在   start'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:104:in 运行'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ command.rb:83:在   block in run_process'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/application.rb:249:in 调用'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/守护进程-1.1.4 / LIB /守护进程/ application.rb中:249:在   block in start_proc'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/daemonize.rb:197:in 调用'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/守护进程-1.1.4 / LIB /守护进程/ daemonize.rb:197:在   call_as_daemon'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/application.rb:253:in start_proc'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/守护进程-1.1.4 / LIB /守护进程/ application.rb中:293:在   start'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/controller.rb:70:in 运行'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/守护进程-1.1.4 / LIB / daemons.rb:195:在   block in run_proc'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/cmdline.rb:109:in 调用'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/守护进程-1.1.4 / LIB /守护进程/ cmdline.rb:109:在   catch_exceptions'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons.rb:194:in run_proc'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ command.rb:81:在   run_process'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:75:in 阻止   守护进程'\ N /用户/约翰/ .rvm /宝石/红宝石1.9.2-P290 /宝石/ delayed_job的-2.1.4 / LIB /延迟/ command.rb:73:在   times'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:73:in daemonize'\ nscript / delayed_job:5:in''| 2011-09-06 07:42:21 |   NULL | 2011-09-06 07:43:00 | NULL | 2011-09-06 07:40:07 |   2011-09-06 07:43:00 |

3 个答案:

答案 0 :(得分:5)

我在谷歌搜索同样的问题,我找到了解决方案(这对我有用)。

将这两行添加到config / application.rb

的头部
  

要求'yaml'

     

YAML :: ENGINE.yamler ='syck'

然后,重启你的服务器(webrick / thin / whatever)和delayed_job (bundle exec ./script/delayed_job restart)

进行。

答案 1 :(得分:1)

我遇到了同样的问题。如果你使用瘦,请尝试“捆绑exec瘦启动”。它对我有用。

答案 2 :(得分:0)

尝试更改方法定义

 def self.course_signup 

 studentmailer = StudentMailer.new

因为现在你从类调用方法但方法属于对象