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.
[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
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.
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