我正在通过 tobi 执行延迟作业,当我运行延迟作业时,但 fbLikes 计数都是错误的,而且每次我再添加一家公司时,它似乎都会增加。不知道逻辑错在哪里。我之前测试过的 fbLikes 方法和它的工作原理(在我更改为 delay_job 之前)不确定“1”来自哪里......
[输出]
coca-cola
http://www.cocacola.com
Likes: 1 <--- Not sure why the fbLikes is 1 and it increment with second company fbLikes is 2 and so on...
.
[Worker(host:aname.local pid:1400)] Starting job worker
[Worker(host:aname.local pid:1400)] CountJob completed after 0.7893
[Worker(host:aname.local pid:1400)] 1 jobs processed at 1.1885 j/s, 0 failed ...
我正在模型中运行延迟作业并尝试运行计算 facebook 喜欢的作业
这是我的代码。[lib/count_rb.job]
require 'net/http'
class CountJob< Struct.new(:fbid)
def perform
uri = URI("http://graph.facebook.com/#{fbid}")
data = Net::HTTP.get(uri)
return JSON.parse(data)['likes']
end
end
[公司型号]
before_save :fb_likes
def fb_likes
self.fbLikes = Delayed::Job.enqueue(CountJob.new(self.fbId))
end