rails:延迟作业进度条

时间:2015-06-10 12:59:09

标签: ruby-on-rails delayed-job progress

我正在尝试向用户显示在延迟作业中运行的任务的进度条。 我正在使用数据库中的延迟作业填充大量数据。

class ImportSchoolsAndDistricts < Struct.new(:import, :content)
  def perform
    total = content.size
    content.each_with_index do |record,index|
      # create records here
      import.update_attribute(:progress, (index + 1)/total*100)
    end
  end
end

:import是具有属性progress的导入模型的实例。我将使用此progress属性以百分比的形式向用户显示作业状态。

progress的更新并未持续发生。它只更新两次:一次在开始时,一次在结束时,因此我获得的进展值为0%和100%。

由于我使用的是ruby 1.9,我无法使用progress_bar https://github.com/d4be4st/progress_job(需要Ruby 2.0.0)

0 个答案:

没有答案
相关问题