5
votes

I have a rails 3.0.5 app that was working just fine with delayed_job 2.1.4.

It's been a few weeks since I touched the app, but I just went to tweak it and noticed that delayed_job is broken. Specifically, any call to delayed_job returns an "undefined method" error on the method after delay. (eg StudentMailer.delay.student_mail('test') returns "undefined method" on "student_mail") I cannot figure out why. A few things:

  • Replacing StudentMailer.delay.student_mail('test') with StudentMailer.student_mail('test').deliver delivers the mail just fine.

  • Have not changed any gem versions on the site, they've been locked since development

  • RVM has been uninstalled & reinstalled

  • Happens across all mailer methods

Code & error below:

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 (Mailer called on 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:in invoke_job'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in block (2 levels) in run'\n/Users/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:58:in timeout'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:120:in block in run'\n/Users/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in realtime'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:119:in run'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:177:in 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 block in work_off'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:103:in 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/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:78:in block (2 levels) in start'\n/Users/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in realtime'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:77:in 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 loop'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/worker.rb:74:in start'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:104:in run'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:83:in 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 call'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/application.rb:249:in 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 call'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/daemonize.rb:197:in 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/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/application.rb:293:in start'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/controller.rb:70:in run'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons.rb:195:in 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 call'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/daemons-1.1.4/lib/daemons/cmdline.rb:109:in 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/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:81:in run_process'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:75:in block in daemonize'\n/Users/john/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-2.1.4/lib/delayed/command.rb:73:in 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

3 Answers

5
votes

I was Googling the same issue, and I found a fix for this(it worked for me).

add these two lines to the head of your config/application.rb

require 'yaml'

YAML::ENGINE.yamler = 'syck'

then, restart your server(webrick/thin/whatever) and delayed_job (bundle exec ./script/delayed_job restart)

done.

1
votes

I had the same problem. If you are using thin, try doing "bundle exec thin start". It worked for me.

0
votes

try to change method definition

 def self.course_signup 

or

 studentmailer = StudentMailer.new

because now you call method from class but method belongs to object