Merge pull request #3144 from betagouv/frederic/fix_2180/progress_report_edge_cases

[#2180] Fix edge cases for progress report
This commit is contained in:
Frederic Merizen 2018-12-07 16:58:31 +01:00 committed by GitHub
commit c9d34c0e86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,7 +45,9 @@ class ProgressReport
@count = count @count = count
@total = [@count, @total].max @total = [@count, @total].max
end end
@per_10_000 = 10_000 * @count / @total if @total&.nonzero?
@per_10_000 = 10_000 * @count / @total
end
end end
def print_progress def print_progress
@ -53,10 +55,14 @@ class ProgressReport
percent = sprintf('%5.1f%%', @per_10_000 / 100.0) percent = sprintf('%5.1f%%', @per_10_000 / 100.0)
total = @total.to_s total = @total.to_s
count = @count.to_s.rjust(total.length) count = @count.to_s.rjust(total.length)
rake_print("\r#{percent} (#{count}/#{total}) [#{format_duration(elapsed)}/#{format_duration(elapsed * 10_000 / @per_10_000)}]") rake_print("\r#{percent} (#{count}/#{total}) [#{format_duration(elapsed)}/#{format_duration(elapsed * 10_000.0 / @per_10_000)}]")
end end
def format_duration(seconds) def format_duration(seconds)
Time.at(seconds).utc.strftime('%H:%M:%S') if seconds.finite?
Time.at(seconds).utc.strftime('%H:%M:%S')
else
'--:--:--'
end
end end
end end