dor-services-client 6.1.0 → 6.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: f324272fcd773616044c4ddc11f93664d52efa263f47cdcc21059dd07bee7562
4
- data.tar.gz: 1abbe32573c71a368d69a46ce1a18c6eb587a35a6e2ad7e2dead9670e9c276a5
3
+ metadata.gz: 9bfa9e7819d9794826fb95861eb36bcaa9f426280dd96267b2739f4693606c1f
4
+ data.tar.gz: df0c3d033e30d17ecafed72c66406dc33ae6f8f682434e43feb8a47f9b97358f
5
5
  SHA512:
6
- metadata.gz: ece82eaa29c075d3e6b5c66d18e133f200984c7ef0ab5cdb810ed11e729de893fe8be0e5610a67452dd6fbc5cb0264e9aa6983f8d3d342926e04c9ad45a39b33
7
- data.tar.gz: 906962b8dabe3ebb34fab6a41ffa8dd52e5c1e68315587d3763a8897cf3d2fd182929d3cd3b1e9e58de6e988415ddd351071e44ee3bcaf42cafde272e1d35269
6
+ metadata.gz: 4edbf5f3ee992ed4accae4225e16d294c9b5aeb8d9c7507164afd2242933040cbf4067b79388c254dfab6263a224d8d6b85655a07a5cf22f4236f41318d5297a
7
+ data.tar.gz: d52a6f01e86def397871069447cda06886fd1fc5e94f9af98c651d6d8b7e88e8b170530e89bbf35b89d764aa0ad82a743eb9a1434723db45af920df7a7a4d34e
data/README.md CHANGED
@@ -40,11 +40,16 @@ private
40
40
 
41
41
  def client
42
42
  @client ||= Dor::Services::Client.configure(url: Settings.dor_services.url,
43
- token: Settings.dor_services.token)
43
+ token: Settings.dor_services.token,
44
+ enable_get_retries: true)
44
45
  end
45
46
  ```
46
47
 
47
- Note that the client may **not** be used without first having been configured, and the `url` keyword is **required**. The `token` argument is optional (though when using the client with staging and production servers, you will always need to supply it in practice). For more about dor-services-app's token-based authentication, see [its README](https://github.com/sul-dlss/dor-services-app#authentication).
48
+ Note:
49
+ * The client may **not** be used without first having been configured
50
+ * The `url` keyword is **required**.
51
+ * The `token` argument is optional (though when using the client with staging and production servers, you will always need to supply it in practice). For more about dor-services-app's token-based authentication, see [its README](https://github.com/sul-dlss/dor-services-app#authentication).
52
+ * The `enable_get_retries` argument is optional. When enabled, it will perform retries of `GET` requests only. This should only be used in situations in which blocking is not an issue, e.g., an asynchronous job.
48
53
 
49
54
  ## API Coverage
50
55
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # Wraps connections to allow GET requests to be retriable.
7
+ class ConnectionWrapper
8
+ delegate :get, to: :get_connection
9
+ delegate :post, :delete, :put, :patch, to: :connection
10
+
11
+ def initialize(connection:, get_connection:)
12
+ @connection = connection
13
+ @get_connection = get_connection
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :connection, :get_connection
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Services
5
5
  class Client
6
- VERSION = '6.1.0'
6
+ VERSION = '6.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -79,9 +79,11 @@ module Dor
79
79
  class << self
80
80
  # @param [String] url the base url of the endpoint the client should connect to (required)
81
81
  # @param [String] token a bearer token for HTTP authentication (required)
82
- def configure(url:, token:)
82
+ # @param [Boolean] enable_get_retries retries get requests on errors
83
+ def configure(url:, token:, enable_get_retries: false)
83
84
  instance.url = url
84
85
  instance.token = token
86
+ instance.enable_get_retries = enable_get_retries
85
87
 
86
88
  # Force connection to be re-established when `.configure` is called
87
89
  instance.connection = nil
@@ -92,18 +94,22 @@ module Dor
92
94
  delegate :background_job_results, :marcxml, :objects, :object, :virtual_objects, to: :instance
93
95
  end
94
96
 
95
- attr_writer :url, :token, :connection
97
+ attr_writer :url, :token, :connection, :enable_get_retries
96
98
 
97
99
  private
98
100
 
99
- attr_reader :token
101
+ attr_reader :token, :enable_get_retries
100
102
 
101
103
  def url
102
104
  @url || raise(Error, 'url has not yet been configured')
103
105
  end
104
106
 
105
107
  def connection
106
- @connection ||= Faraday.new(url) do |builder|
108
+ @connection ||= ConnectionWrapper.new(connection: build_connection, get_connection: build_connection(with_retries: enable_get_retries))
109
+ end
110
+
111
+ def build_connection(with_retries: false)
112
+ Faraday.new(url) do |builder|
107
113
  builder.use ErrorFaradayMiddleware
108
114
  builder.use Faraday::Request::UrlEncoded
109
115
 
@@ -113,6 +119,10 @@ module Dor
113
119
  builder.adapter Faraday.default_adapter
114
120
  builder.headers[:user_agent] = user_agent
115
121
  builder.headers[TOKEN_HEADER] = "Bearer #{token}"
122
+ if with_retries
123
+ builder.request :retry, max: 4, interval: 1,
124
+ backoff_factor: 2, exceptions: ['Faraday::Error', 'Timeout::Error']
125
+ end
116
126
  end
117
127
  end
118
128
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-services-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-04-30 00:00:00.000000000 Z
12
+ date: 2020-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -232,6 +232,7 @@ files:
232
232
  - lib/dor/services/client/async_result.rb
233
233
  - lib/dor/services/client/background_job_results.rb
234
234
  - lib/dor/services/client/collections.rb
235
+ - lib/dor/services/client/connection_wrapper.rb
235
236
  - lib/dor/services/client/embargo.rb
236
237
  - lib/dor/services/client/error_faraday_middleware.rb
237
238
  - lib/dor/services/client/events.rb