I am trying to show user a progress bar for a task running in the delayed job. I am populating a large amount of data using delayed job in the database like this.
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
end
:import
is an instance of Import model with an attribute progress
. I will use this progress
attribute to display to the user the status of job as a percentage.
But the update of progress
is not occurring continuously. It is updating only twice: once at the beginning and once at the end, so the values i am getting for progress are 0% and 100%.
Since i am using ruby 1.9, I cannot use progress_bar https://github.com/d4be4st/progress_job (requires Ruby 2.0.0)