Delayed_job in rails raising 'nil object' error

Go To StackoverFlow.com

0

I'm struggling to use Delayed_job (collective idea v2.0 in a Rails 2.3.8 app).

I'm calling the job from an application_controller method:

...
Delayed::Job.enqueue(S3MoverJob.new(docs))

Where docs is a Hash with ids and names of files.

At my Lib directory I have the class S3MoverJob:

class S3MoverJob < Struct.new(:docs)

  def perform
    #setup connection to Amazon
    ...
    #connect
    ...

    #loop to move files not transfered already
    docs.each do |id,file_name|
     # Move file
      begin
        doc = Document.find(id)
        ... perform actions
      rescue Exception => exc
         raise "failed!"
      end
    end
  end

end

The problem is that it's raising: S3MoverJob failed with NoMethodError: You have a nil object when you didn't expect it!

I looked into the handler, in the DB, and it was delivering to the perform method the Yaml file with the list of ids and file names, like this:

docs:
   3456: name_of_file_01.png
   4567: name_of_file_02.txt

What am I missing? Thanks for helping me.

2012-04-05 22:44
by Valadares
You might want to mark some answers as accepted for the questions you've previously asked, otherwise noone will want to answer you - Abe Voelker 2012-04-06 03:38
A stacktrace would be helpful - betamatt 2012-04-06 18:47
What it throws (development):

[Worker(host:iMac pid:1789)] Starting job worker [Worker(host:iMac pid:1789)] S3MoverJob failed with NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] - 0 failed attempts [Worker(host:iMac pid:1789)] 1 jobs processed at 68.9376 j/s, 1 failed ... [Worker(host:iMac pid:1789)] S3MoverJob failed with NoMethodError: You have a nil object when you didn't expect it!Valadares 2012-04-07 02:01



0

My fault. I didn't know it was an idenpendent process and needed some requirements:

require 'yaml'
require 'uri'
class Document < ActiveRecord::Base
end

After that, everything works fine.

Thanks anyway.

2012-04-07 12:59
by Valadares


0

I think you should puts more information for debug. Such as: add statements like 'Rails.logger.info "some stuff"' under the perform method to see where the exception been throw

2012-04-06 04:43
by LeoShi
I've been commenting parts of the code, and it's raising exception on: docs.each do |id,file_name| Probably, it's not recognizing the hash I've sent to it properly - Valadares 2012-04-06 21:34
Ads