I'm just starting to learn the use of the delayed_job gem.
To test it, I added "delayed" to the welcome message function and changed this call from
UserMailer.welcome_email(self).deliver
to
UserMailer.delay.welcome_email(self)
This is called inside the after_create user model. I see that the record appears in the delayed_job table after the function is executed. Now when I run "rake jobs: work" on the command line, the task starts, but gives errors below
[Worker(host:Sanjay-PC pid:7008)] Starting job worker [Worker(host:Sanjay-PC pid:7008)] Class#welcome_email failed with NoMethodError: undefined method `welcome_email' for #<Class:0x4871d60> - 0 failed attempts [Worker(host:Sanjay-PC pid:7008)] 1 jobs processed at 0.0939 j/s, 1 failed ...
I think if I changed the declaration of the welcome_email method to the class method as
def self.welcome_email(user)
(added self. in front), which may help. But then when I run rake jobs: work, I get the following error:
rake aborted! undefined method `welcome_email' for class `UserMailer' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain' C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.4/lib/delayed/message_sending.rb:50:in `handle_asynchronously' c:/mgn/mgn-r3/app/mailers/user_mailer.rb:10:in `<class:UserMailer>' c:/mgn/mgn-r3/app/mailers/user_mailer.rb:1:in `<top (required)>' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:454:in `load' <Stack truncated>
It seems he now knows the class as UserMailer, but somehow he does not see the method of the welcome_email class.
I am on Rails 3.0.5, Ruby 1.9.2p180, and the installed file delayed_job - 2.1.4 - on Windows
It does not seem to find any related answers.
Thanks for your thoughts.
-S
Adding UserMailer code for @pjammer request
class UserMailer < ActionMailer::Base default :from => " from@example.com " def welcome_email(user) @user = user @url = "http://example.com/login" mail(:to => user.email, :subject => "Welcome to My Awesome Site") end end