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:
commit
c9d34c0e86
1 changed files with 9 additions and 3 deletions
|
@ -45,18 +45,24 @@ class ProgressReport
|
|||
@count = count
|
||||
@total = [@count, @total].max
|
||||
end
|
||||
if @total&.nonzero?
|
||||
@per_10_000 = 10_000 * @count / @total
|
||||
end
|
||||
end
|
||||
|
||||
def print_progress
|
||||
elapsed = Time.zone.now - @start
|
||||
percent = sprintf('%5.1f%%', @per_10_000 / 100.0)
|
||||
total = @total.to_s
|
||||
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
|
||||
|
||||
def format_duration(seconds)
|
||||
if seconds.finite?
|
||||
Time.at(seconds).utc.strftime('%H:%M:%S')
|
||||
else
|
||||
'--:--:--'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue