【发布时间】:2012-04-19 16:34:51
【问题描述】:
我正在努力使用 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
我错过了什么?谢谢你帮助我。
【问题讨论】:
-
对于您之前提出的问题,您可能希望将某些答案标记为已接受,否则没有人愿意回答您。
-
堆栈跟踪会很有帮助。
-
它抛出了什么(开发):
[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!
标签: ruby-on-rails ruby amazon-s3 delayed-job