purl_fetcher-client 3.0.1 → 3.2.0
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6710de91c16b6a4a1a77e5e29c48a7b21397b1a41b97c141d3f493922555121
|
|
4
|
+
data.tar.gz: 2dc4d0f5982f131cef6dc3cb9d0bba4d509d65cb20345c3ca96eda8709fa4704
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20be3cc789a26ee629d4d6e5037decc83b966b3cc3dd040998f476bef0440a4f34cd424ad67bf213b4fb9044ebb2dcc3cf0c97670f843112b4d4fa1d9b4bf2b0
|
|
7
|
+
data.tar.gz: db547c44f01e51f9b40d73a06c956b36d667c8cb0cc13452e01968f676746ff1035b7104422c4d84882a75db6e16af77ab198e58ba67e1bf6b000fa719e3142d
|
|
@@ -13,23 +13,25 @@ module PurlFetcher
|
|
|
13
13
|
# @param [String] version the version of the item
|
|
14
14
|
# @param [DateTime] version_date the version date
|
|
15
15
|
# @param [Boolean] must_version whether the item must be versioned
|
|
16
|
-
|
|
16
|
+
# @param [Boolean] retriable whether to retry on failure
|
|
17
|
+
def initialize(cocina:, file_uploads:, version:, version_date:, must_version:, retriable: true)
|
|
17
18
|
@cocina = cocina
|
|
18
19
|
@file_uploads = file_uploads
|
|
19
20
|
@version = version
|
|
20
21
|
@version_date = version_date
|
|
21
22
|
@must_version = must_version
|
|
23
|
+
@retriable = retriable
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def publish
|
|
25
27
|
logger.debug("Starting a publish request for: #{druid}")
|
|
26
|
-
client.put(path:, body:)
|
|
28
|
+
client.put(path:, body:, retriable:)
|
|
27
29
|
logger.debug("Publish request complete")
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
private
|
|
31
33
|
|
|
32
|
-
attr_reader :cocina, :file_uploads, :version, :version_date, :must_version
|
|
34
|
+
attr_reader :cocina, :file_uploads, :version, :version_date, :must_version, :retriable
|
|
33
35
|
|
|
34
36
|
def druid
|
|
35
37
|
cocina.externalIdentifier
|
|
@@ -20,6 +20,13 @@ class PurlFetcher::Client::Reader
|
|
|
20
20
|
paginated_get("/collections/druid:#{druid.delete_prefix('druid:')}/purls", "purls").each { |member| yield member }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# @return [Hash] a hash including the item's druid and its last updated time
|
|
24
|
+
def released_to(target)
|
|
25
|
+
return to_enum(:released_to, ERB::Util.url_encode(target)) unless block_given?
|
|
26
|
+
|
|
27
|
+
retrieve_json("/released/#{target}").each { |item| yield item }
|
|
28
|
+
end
|
|
29
|
+
|
|
23
30
|
# @return [Array<Hash<String,String>>] a list of hashes where the key is a digest and the value is a filepath/filename
|
|
24
31
|
# @raise [PurlFetcher::Client::NotFoundResponseError] if item is not found
|
|
25
32
|
# @raise [PurlFetcher::Client::ResponseError] if the response is not successful
|
|
@@ -32,7 +39,7 @@ class PurlFetcher::Client::Reader
|
|
|
32
39
|
|
|
33
40
|
##
|
|
34
41
|
# @return [Hash] a parsed JSON hash
|
|
35
|
-
def retrieve_json(path, params)
|
|
42
|
+
def retrieve_json(path, params = {})
|
|
36
43
|
response = conn.get(path, params)
|
|
37
44
|
|
|
38
45
|
unless response.success?
|
data/lib/purl_fetcher/client.rb
CHANGED
|
@@ -76,8 +76,9 @@ module PurlFetcher
|
|
|
76
76
|
# @param path [String] the path for the API request
|
|
77
77
|
# @param body [String] the body of the POST request
|
|
78
78
|
# @param headers [Hash] extra headers to add to the SDR API request
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
# @param retriable [Boolean] whether to retry on failure
|
|
80
|
+
def put(path:, body: nil, headers: {}, retriable: false)
|
|
81
|
+
response = connection(retriable:).put(path) do |request|
|
|
81
82
|
request.body = body if body
|
|
82
83
|
request.headers = default_headers.merge(headers)
|
|
83
84
|
end
|
|
@@ -91,12 +92,23 @@ module PurlFetcher
|
|
|
91
92
|
|
|
92
93
|
Config = Data.define(:url, :logger, :token)
|
|
93
94
|
|
|
94
|
-
def connection
|
|
95
|
+
def connection(retriable: false)
|
|
95
96
|
Faraday.new(
|
|
96
97
|
url: config.url,
|
|
97
98
|
headers: default_headers,
|
|
98
99
|
request: default_request_options
|
|
99
100
|
) do |conn|
|
|
101
|
+
if retriable
|
|
102
|
+
conn.request :retry,
|
|
103
|
+
max: 3,
|
|
104
|
+
interval: 15,
|
|
105
|
+
backoff_factor: 2,
|
|
106
|
+
exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS,
|
|
107
|
+
retry_statuses: [ 500 ],
|
|
108
|
+
retry_block: lambda { |env, _options, retries_remaining, exception|
|
|
109
|
+
config.logger.warn("Retrying request to #{env.url} (#{retries_remaining} retries remaining): #{exception&.message}")
|
|
110
|
+
}
|
|
111
|
+
end
|
|
100
112
|
conn.response :json
|
|
101
113
|
end
|
|
102
114
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: purl_fetcher-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0
|
|
4
|
+
version: 3.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Beer
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
148
148
|
- !ruby/object:Gem::Version
|
|
149
149
|
version: '0'
|
|
150
150
|
requirements: []
|
|
151
|
-
rubygems_version:
|
|
151
|
+
rubygems_version: 4.0.6
|
|
152
152
|
specification_version: 4
|
|
153
153
|
summary: Traject-compatible reader implementation for streaming data from purl-fetcher
|
|
154
154
|
test_files: []
|