本文介绍了delay_job_mongoid没有在后端写入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Mongoid模型
I have mongoid model
class RequestResponse
include Mongoid::Document
field :body, type: String
field :job_id, type: Fixnum
field :completed, type: Boolean
end
并且根据Rails Cast我的lib文件夹中有一个类
and according to rails cast I have a class in my lib folder
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
我在控制器中的某个地方打电话了
I called some where in my controller
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的表中
And the result is not stored in the table for rr if i check
rr.body
仍然没有人可以帮助我
推荐答案
我的工作已被静默删除.我已经通过在config/initializers/custom.rb中创建文件并将此行放入
My job was silently deleted. I have fixed the problem by creating a file in config/initializers/custom.rb and put this line
require File.expand_path(File.join(File.dirname(__FILE__), "../../lib/my_job"))
这篇关于delay_job_mongoid没有在后端写入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!