Upgrading to Rails 3.2.2: How to solve the 'un

2019-05-16 16:49发布

问题:

I am running Ruby on Rails 3.2.2 from 3.1.0. I have the issue

undefined method send_register_email\' for #<Syck::DomainType:0x0000012d2346b8>\n/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/performable_mailer.rb:6:in perform ...

with the DelayedJob gem that many other people have tried to solve: someone made successfully that, others no. I am in the latter category, also if I tried all solutions I've found on the Web.

At this time, in my Gemfile I have:

gem 'rails', '3.2.2'
gem "rake"
...
gem 'delayed_job_active_record'
...

Before upgrading Rails, in my Gemfile I had:

gem 'rails', '~> 3.1.0'
gem "rake"
...
# I also used the following statement by running Rails 3.2.2 but it didn't work.
gem 'delayed_job'
...

In order to send e-mail messages, in my controllers I use code link the following:

::Users::Mailer.delay.send_register_email(@user)

In my APPLICATION_ROOT/app/mailers/users/mailer.rb file I have:

class Users::Mailer < ActionMailer::Base
  ...

  def send_register_email(user)
    ...
  end
end

Before updating to Rails 3.2.2 all was working as well. Now I get the error mentioned above, in the introduction text. How can I try to solve the Delayed Job issue?


I noted that in the database table related to the delayed_job_active_record gem should be a column named 'queue' (see the "Gory Details" section in the official documentation for more information). However, since I was using gem 'delayed_job' it was present in that database table. Can be that the problem?


Another thing I noted is the following (but I think that isn't the problem, for now):

$ rake jobs:work
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /<ABSOLUTE_PATH>/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /<ABSOLUTE_PATH>/Rakefile:7)
[Worker(host:<MY_USER>.local pid:76826)] Starting job worker



The following is what is present in the DelayedJob last_error database table column:

{undefined method `send_register_email' for #<Syck::DomainType:0x0000010228a840>
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/performable_mailer.rb:6:in `perform'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/backend/base.rb:94:in `block in invoke_job'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `call'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `block in initialize'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `call'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `execute'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/backend/base.rb:91:in `invoke_job'
/<ABSOLUTE_PATH>/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:162:in `block (2 levels) in run'
/<ABSOLUTE_PATH>/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:58:in `timeout'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:162:in `block in run'
/<ABSOLUTE_PATH>//.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:161:in `run'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:218:in `block in reserve_and_run_one_job'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `block in initialize'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `execute'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:218:in `reserve_and_run_one_job'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:146:in `block in work_off'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:145:in `times'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:145:in `work_off'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:117:in `block (4 levels) in start'
/<ABSOLUTE_PATH>//.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:116:in `block (3 levels) in start'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `block in initialize'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `execute'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:113:in `block (2 levels) in start'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:112:in `loop'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:112:in `block in start'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/plugins/clear_locks.rb:7:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:78:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:60:in `block in initialize'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:78:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:78:in `block in add'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:65:in `execute'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/worker.rb:111:in `start'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/<ABSOLUTE_PATH>//.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/<ABSOLUTE_PATH>//.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'

回答1:

We managed to solve Syck / Psych weirdness in our app by ensuring that setting the YAML parser to Syck was the absolute first thing done when initializing. The reason you can sometimes run into issues is that DelayedJob initializes differently depending on which YAML parser you're using, and if the parser changes during initialization, DelayedJob will probably get it wrong.

Add this to the very top of boot.rb, and see if it helps:

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


回答2:

If you are using bundler try prefixing the script or rake task with "bundle exec" e.g.

bundle exec script/delayed_job -n 2 start 

It did the trick for us.