commit
00150d16e6
3 changed files with 11 additions and 5 deletions
|
@ -4,7 +4,7 @@ module ActiveStorage
|
||||||
@adapter = Cellar::CellarAdapter.new(access_key_id, secret_access_key, bucket)
|
@adapter = Cellar::CellarAdapter.new(access_key_id, secret_access_key, bucket)
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(key, io, checksum: nil)
|
def upload(key, io, checksum: nil, **)
|
||||||
instrument :upload, key: key, checksum: checksum do
|
instrument :upload, key: key, checksum: checksum do
|
||||||
@adapter.session { |s| s.upload(key, io, checksum) }
|
@adapter.session { |s| s.upload(key, io, checksum) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ module Cellar
|
||||||
@signer = signer
|
@signer = signer
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(key, io, checksum: nil, **)
|
def upload(key, io, checksum)
|
||||||
with_io_length(io) do |io, length|
|
with_io_length(io) do |io, length|
|
||||||
request = Net::HTTP::Put.new("/#{key}")
|
request = Net::HTTP::Put.new("/#{key}")
|
||||||
request.content_type = 'application/octet-stream'
|
request.content_type = 'application/octet-stream'
|
||||||
|
|
|
@ -45,18 +45,24 @@ class ProgressReport
|
||||||
@count = count
|
@count = count
|
||||||
@total = [@count, @total].max
|
@total = [@count, @total].max
|
||||||
end
|
end
|
||||||
|
if @total&.nonzero?
|
||||||
@per_10_000 = 10_000 * @count / @total
|
@per_10_000 = 10_000 * @count / @total
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def print_progress
|
def print_progress
|
||||||
elapsed = Time.zone.now - @start
|
elapsed = Time.zone.now - @start
|
||||||
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)
|
||||||
|
if seconds.finite?
|
||||||
Time.at(seconds).utc.strftime('%H:%M:%S')
|
Time.at(seconds).utc.strftime('%H:%M:%S')
|
||||||
|
else
|
||||||
|
'--:--:--'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue