我有 mongoid 模型
class RequestResponse
include Mongoid::Document
field :body, type: String
field :job_id, type: Fixnum
field :completed, type: Boolean
end
根据rails cast,我的lib文件夹中有一个类
class MyJob < Struct.new(:session, :url, :r_id)
def perform
rr = RequestResponse.find(r_id)
session = YAML.load session
rr.body = session.get(url).body
rr.completed = true
rr.save
end
end
我在控制器中的某个地方调用了
rr = RequestResponse.new
rr.save
Delayed::Job.enqueue(MyJob.new(session.to_yaml, url, rr.id),3)
我可以看到
rake jobs:work
1 jobs processed at 19.3392 j/s, 0 failed ...
如果我检查,结果不会存储在 rr 的表中
rr.body
仍然没有任何人可以帮助我提前谢谢