From 84cfdcf617afe1344134f3496a64c5c584d86c52 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 7 Dec 2018 16:45:14 +0100 Subject: [PATCH 1/2] [#2180] Fix edge cases for progress report --- lib/tasks/task_helper.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tasks/task_helper.rb b/lib/tasks/task_helper.rb index 5ed9d6b7a..04ef5d32b 100644 --- a/lib/tasks/task_helper.rb +++ b/lib/tasks/task_helper.rb @@ -45,7 +45,9 @@ class ProgressReport @count = count @total = [@count, @total].max end - @per_10_000 = 10_000 * @count / @total + if @total&.nonzero? + @per_10_000 = 10_000 * @count / @total + end end def print_progress @@ -53,10 +55,14 @@ class ProgressReport 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) - Time.at(seconds).utc.strftime('%H:%M:%S') + if seconds.finite? + Time.at(seconds).utc.strftime('%H:%M:%S') + else + '--:--:--' + end end end From 35fc41fb9ff84c7d7d883651a7b722e0087d3e3b Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 7 Dec 2018 16:59:25 +0100 Subject: [PATCH 2/2] Really fix #3133 --- lib/active_storage/service/cellar_service.rb | 2 +- lib/cellar/cellar_adapter.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_storage/service/cellar_service.rb b/lib/active_storage/service/cellar_service.rb index f704fcf49..43f2d0632 100644 --- a/lib/active_storage/service/cellar_service.rb +++ b/lib/active_storage/service/cellar_service.rb @@ -4,7 +4,7 @@ module ActiveStorage @adapter = Cellar::CellarAdapter.new(access_key_id, secret_access_key, bucket) end - def upload(key, io, checksum: nil) + def upload(key, io, checksum: nil, **) instrument :upload, key: key, checksum: checksum do @adapter.session { |s| s.upload(key, io, checksum) } end diff --git a/lib/cellar/cellar_adapter.rb b/lib/cellar/cellar_adapter.rb index 97369c2c5..1a1ed400c 100644 --- a/lib/cellar/cellar_adapter.rb +++ b/lib/cellar/cellar_adapter.rb @@ -34,7 +34,7 @@ module Cellar @signer = signer end - def upload(key, io, checksum: nil, **) + def upload(key, io, checksum) with_io_length(io) do |io, length| request = Net::HTTP::Put.new("/#{key}") request.content_type = 'application/octet-stream'