delayed job - Rails: Absolutely stumped with delayed_job. Not receiving arguments anywhere -


i'm trying send mail in rails 3 application using collectiveidea's delayed_job. if try send mail regularly (.deliver) works fine, switch delayed job, things fall pieces.

the standard error in delayed_job mysql table is:

{undefined method `name' nil:nilclass...

where 'name' first argument in mailer's view (@contact.name). works fine if take delayed_job out again.

if remove references @contact in view, get

{a sender (return-path, sender or from) required send message

in short, doesn't seem understanding arguments @ all.

all relevant code below - if has suggestions appreciated

controller

  def sendmail     @contact = contact.new(params[:contact])     if @contact.save       contactmailer.delay.contact_mail(@contact)       flash[:notice] = 'your message has been sent'       redirect_to root_path     else       render :action => 'index'     end   end 

mailer:

class contactmailer < actionmailer::base   default :from => "my@email.address"      def contact_mail(contact)     @contact = contact     mail(:to => 'my@email.address', :subject => 'contact form query', :from => 'my@email.address', :content_type => 'text/plain')   end   handle_asynchronously :contact_mail, :run_at => proc.new { 2.seconds.from_now } end 

mailer view:

you have received new query: -----------------------------------  <%= @contact.name %>  <%= @contact.business %>  <%= @contact.phone %>  ----------------------- <%= @contact.message %> ----------------------- 

initializer:

delayed::worker.destroy_failed_jobs = false delayed::worker.max_run_time = 5.weeks 

and finally, full error message:

    {undefined method `name' nil:nilclass  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'  /users/john/websites/rails/indevelopment/connectted/app/views/contact_mailer/contact_mail.html.erb:4:in `_app_views_contact_mailer_contact_mail_html_erb___3386534441642202773_2166008980__4301703149293725172'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `block in render'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:54:in `instrument'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/template.rb:127:in `render'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:59:in `block in _render_template'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `block in instrument'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:56:in `_render_template'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:26:in `render'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:114:in `_render_template'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:108:in `render_to_body'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:101:in `render_to_string'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:92:in `render'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/deprecated_api.rb:111:in `render'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:210:in `block in create_parts'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:208:in `each'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:208:in `create_parts'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/deprecated_api.rb:143:in `create_parts'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:77:in `process'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:446:in `process'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:441:in `initialize'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:425:in `new'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:425:in `method_missing'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/performable_mailer.rb:6:in `perform'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/backend/base.rb:83:in `invoke_job'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:119:in `block (2 levels) in run'  /users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed /worker.rb:119:in `block in run'  /users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:118:in `run'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:176:in `reserve_and_run_one_job'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:103:in `block in work_off'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:102:in `times'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:102:in `work_off'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:77:in `block (2 levels) in start'  /users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:76:in `block in start'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:73:in `loop'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:73:in `start'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:100:in `run'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:79:in `block in run_process'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `call'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `block in start_proc'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call_as_daemon'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:254:in `start_proc'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:294:in `start'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/controller.rb:70:in `run'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons.rb:193:in `block in run_proc'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `call'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `catch_exceptions'  /users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons.rb:192:in `run_proc'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:78:in `run_process'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:72:in `block in daemonize'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:70:in `times'  /users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:70:in `daemonize' script/delayed_job:5:in `<main>' | 
share|improve question
1  
i'm assuming none of answers below solved problem? did ever figure out? i'm having similar issue, except in case jobs "succeeding", nothing happening. added logging first line , got nothing. i'm suspecting it's related either a) rvm (my app uses 1.9.2, system ruby 1.8.7) or b) mongoid somehow (although it's finding jobs fine). i'm going investigate rvm thing, although i'm not sure how daemon run under 1.9.2 @ point. – brad apr 3 '11 @ 5:26
    
hi brad - unfortunately no answer ever found. think resorted manually cronning out mails server manually, isn't ideal solution. – plankton apr 3 '11 @ 22:31
    
bummer. haven't figured out either. in case if create job in rails console , call "delayed::worker.new.start", work. if run "script/delayed_job start" in application's root directory in terminal, absolutely nothing. finds jobs, log says "1 job found, 0 failed", nothing has happened. have no idea how debug this, since worker starts in process in case, must related process running in different environment in way. – brad apr 4 '11 @ 4:16
    
nods spent 2 full days on no joy...wish offer more help. – plankton apr 4 '11 @ 5:13
    
found ugly workaround. use activerecord model instead of regular class. luck... – cider feb 10 '13 @ 9:33
up vote 11 down vote accepted

the issue code in mailer taking object instead of objects id:

def contact_mail(contact)     @contact = contact     mail(:to => 'my@email.address', :subject => 'contact form query', :from => 'my@email.address', :content_type => 'text/plain') end 

you should change this:

def contact_mail(contact_id)     @contact = contact.find(contact_id)     mail(:to => 'my@email.address', :subject => 'contact form query', :from => 'my@email.address', :content_type => 'text/plain') end 

never pass actual objects mailer. pass id's , retrieve them upon processing.

share|improve answer

i had same problem, , fixed moving attributes instance variables. so, in view:

<%= @contact.name %> <%= @contact.business %> <%= @contact.phone %> 

becomes:

<%= @name %> <%= @business %> <%= @phone %> 

and looked instance variables in mailer method. so, in mailer:

def contact_mail(contact)     @contact = contact     mail(:to => 'my@email.address', :subject => 'contact form query', :from => 'my@email.address', :content_type => 'text/plain') end 

becomes:

def contact_mail(contact)     @name = contact.name     @business = contact.business     @phone = contact.phone     mail(:to => 'my@email.address', :subject => 'contact form query', :from => 'my@email.address', :content_type => 'text/plain') end 
share|improve answer

why not working? not sure, imagine has actionmailer voodoo.

how working? abstract out delayed job pieces class. have method delayed nothing more send them email; meaning rendering of email done in real time, sending of delayed. should around problem , accomplish asynchronous sending of emails.

share|improve answer

hey might far off, you're not sending params mailer. here's copy of referred_email.rb keep in lib/ dir. call delayed_job:

#my controller delayed::job.enqueue referredemail.new(params[:subject], params[:editor1])  #reffered_email.rb  class referredemail < struct.new(:subject, :editor1)   def perform     (cardreferral.all.map(&:email) - cardsignup.all.map(&:email)).each |cf|       @cf = cardreferral.find_by_email(cf)       notifier.deliver_referred_magic_email(user.find(@cf.user_id), @cf.email, @cf.name, @cf.message, subject, editor1)     end   end end 
share|improve answer

it seems using both:

  contactmailer.delay.contact_mail(@contact) 

and

  handle_asynchronously :contact_mail, :run_at => proc.new { 2.seconds.from_now } 

which should 1 or other. try removing handle_asynchronously , see if fixes problem.

share|improve answer

your answer

 
discard

posting answer, agree privacy policy , terms of service.

not answer you're looking for? browse other questions tagged or ask own question.

Comments