我正在努力使用 Delayed_job(Rails 2.3.8 应用程序中的集体想法 v2.0)。
我从 application_controller 方法调用作业:
...
Delayed::Job.enqueue(S3MoverJob.new(docs))
其中 docs 是带有文件 ID 和名称的哈希。
在我的 Lib 目录中,我有 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
问题是它正在引发:S3MoverJob failed with NoMethodError: You have an nil object when you didn't expect it!
我查看了数据库中的处理程序,它正在将带有 id 和文件名列表的 Yaml 文件传递给 perform 方法,如下所示:
docs:
3456: name_of_file_01.png
4567: name_of_file_02.txt
我错过了什么?谢谢你帮助我。