【发布时间】:2011-12-30 06:13:03
【问题描述】:
我正在为 Resque/Redis 使用 resque-status...
https://github.com/quirkey/resque-status
我基本上想创建一个新的 Sinatra 方法 .. 如下所示。我只有 2 个 JobsWithStatus ,所以它可以返回两个或一个特定的,我真的不在乎。
post '/getstatus' do
# return status here of all kinds (or specific)
end
然后我想使用每 5 秒检查一次状态的轮询计时器在前端通过 jquery 输出完成百分比。
这就是我所拥有的
post '/refresh' do
job_id = PostSaver.create(:length => Forum.count)
status = Resque::Status.get(job_id)
redirect '/'
end
它在文档中说我可以使用 status.pct_complete 但它总是返回 0?即使这样,我还是 ruby 新手,即使变量显示正确的完成百分比,我也不确定如何使该变量在单独的 sinatra 条目中工作(在 /getstatus 而不是 /refresh 中)。
我试过了,但它一直返回 0
post '/refresh' do
job_id = PostSaver.create(:length => Forum.count)
status = Resque::Status.get(job_id)
sleep 20
status.pct_complete.to_s
end
【问题讨论】: