internetdata 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 001e35eb3c0fef97cb13d9cdb22465c663d215253e299bbff9e61cf016b2aa0a
4
- data.tar.gz: aeca5173f71e178c054e3829e89a2715c1d409bc67e352f80d0160eba1c83c86
3
+ metadata.gz: 6341d4fee4674f684594cba1597efad23a7b83d36117a126bc46db283e562320
4
+ data.tar.gz: c5e0c83a281b4ff2d51a45021cd9f5b31263c654c2197d8422ce728a3f062966
5
5
  SHA512:
6
- metadata.gz: 842beb45ab5b427b07dd985412d11cf6cfebd5325c1128e0846fa8d720ab475a0ca66aaf42a557b96675b678b854aa4ce38d50f3edbac9b4c70f3e0b7e3f1554
7
- data.tar.gz: 5d39b5cac31bbba68c748aea0d05e5e4d24fb8153d14a46cfa9f3ec76b6aa0068a5638e58944138d65440da9f494c56d90d30dc516658b841b87e6764cf33e3e
6
+ metadata.gz: 778d2a234d36fb5c9e783fbfdb63df0b1f9bff7f069db19fb677957bd3d36d9ff46dd582a3bb28ab3fb43d31a150f76f538bc80a5cf4decb032e990393bf63ca
7
+ data.tar.gz: e927fa802dfb5b852aa9a3612fe7de4c47ee0b3e7cbe7704c043bd4864c79f5e6aebb00c9e4bb01ef427b13384b7c7eeaa6b0f8581603e87070557f00c11682f
@@ -77,11 +77,7 @@ module InternetData
77
77
  partial = "#{path}.part"
78
78
  begin
79
79
  url = download_url(id, format)
80
- written = Retries.with_retries(@retries) do
81
- # Reopened per attempt, so a retry restarts the file rather than
82
- # appending a second copy of the body to a half-written one.
83
- File.open(partial, 'wb') { |file| stream(url) { |chunk| file.write(chunk) } }
84
- end
80
+ written = File.open(partial, 'wb') { |file| transfer(url) { |chunk| file.write(chunk) } }
85
81
  File.rename(partial, path)
86
82
  rescue StandardError
87
83
  File.delete(partial) if File.exist?(partial)
@@ -99,15 +95,27 @@ module InternetData
99
95
  # not measured with {#metadata}.
100
96
  def download_bytes(id, format)
101
97
  url = download_url(id, format)
102
- Retries.with_retries(@retries) do
103
- bytes = String.new(encoding: Encoding::BINARY)
104
- stream(url) { |chunk| bytes << chunk }
105
- bytes
106
- end
98
+ bytes = String.new(encoding: Encoding::BINARY)
99
+ transfer(url) { |chunk| bytes << chunk }
100
+ bytes
107
101
  end
108
102
 
109
103
  private
110
104
 
105
+ # The transfer of a presigned link, retried only while nothing has reached the
106
+ # block: object storage failing before the body is as transient as any
107
+ # outage, while a body that dies part way is not fetched again, because the
108
+ # bytes already handed over cannot be taken back.
109
+ def transfer(url, &sink)
110
+ delivered = false
111
+ Retries.with_retries(@retries, retry_if: -> { !delivered }) do
112
+ stream(url) do |chunk|
113
+ delivered = true
114
+ sink.call(chunk)
115
+ end
116
+ end
117
+ end
118
+
111
119
  # Runs one transfer of a presigned link, handing each chunk to the block, and
112
120
  # returns the bytes that reached it.
113
121
  #
@@ -11,12 +11,14 @@ module InternetData
11
11
 
12
12
  module_function
13
13
 
14
- def with_retries(retries)
14
+ # `retry_if`, when given, is asked after each retryable failure, and a false
15
+ # answer ends the attempts there.
16
+ def with_retries(retries, retry_if: nil)
15
17
  attempt = 0
16
18
  begin
17
19
  yield
18
20
  rescue Error => e
19
- raise unless e.retryable? && attempt < retries
21
+ raise unless e.retryable? && attempt < retries && (retry_if.nil? || retry_if.call)
20
22
 
21
23
  attempt += 1
22
24
  sleep(delay_for(e, attempt))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InternetData
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: internetdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev