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 +4 -4
- data/lib/internetdata/database_api.rb +18 -10
- data/lib/internetdata/retries.rb +4 -2
- data/lib/internetdata/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6341d4fee4674f684594cba1597efad23a7b83d36117a126bc46db283e562320
|
|
4
|
+
data.tar.gz: c5e0c83a281b4ff2d51a45021cd9f5b31263c654c2197d8422ce728a3f062966
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 =
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
#
|
data/lib/internetdata/retries.rb
CHANGED
|
@@ -11,12 +11,14 @@ module InternetData
|
|
|
11
11
|
|
|
12
12
|
module_function
|
|
13
13
|
|
|
14
|
-
|
|
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))
|
data/lib/internetdata/version.rb
CHANGED