ezid-client 1.9.4 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 916a399e839a1659d16941826b763aa1b9eb85db6363e17bedd321841d640ab0
4
- data.tar.gz: ee00e4aab023ad60d7a6af0e0b1a001e799f1fcf91aec9f1f99011c69d53dd44
3
+ metadata.gz: '0238bbb49530de30773410dba606a4db95117b344d452bbab62e986e06a29df8'
4
+ data.tar.gz: 8d846a6821058d66a956635d8b1863a345f086b1586716aa0fb38e71518ca90f
5
5
  SHA512:
6
- metadata.gz: 68ef7611653242bf7e3aab73bdf5306a37d80573867efbe26cad33c011c38304a8222e4ef09e0f3cde7c7dee50487fc99ebb04ef64fc8d933113250eae53b185
7
- data.tar.gz: 11dd271fd603d7a99d0d08bb6dc58b7c9627fda790acb2cb6f312d15147600274dccacc2e847e299d0005468fc3238dd97a53dbf80095a2beb58bcd07eb948b1
6
+ metadata.gz: 8d37ad9714ab1403568642178f805b6b73e3c0c93df42e3202a262e35db3ad32522caa9aa4b53cc69924dc5732a798b606634b1d6a6c8cf8f25b40d28813fb9c
7
+ data.tar.gz: 536501b2cf78dbd6c276a8c010257df7ef1ad442786f4297d32c92191de17f92f165ca6ad9ae95fef606147f6791453ffbf3aa6fb584eb0e33bb647ab486339d
data/.dockerignore CHANGED
@@ -2,6 +2,7 @@
2
2
  .bundle
3
3
  .config
4
4
  .dockerignore
5
+ .git
5
6
  .github
6
7
  .gitignore
7
8
  Dockerfile
@@ -19,7 +19,7 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.7', '3.0', '3.1']
22
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v2
data/Dockerfile CHANGED
@@ -4,10 +4,10 @@ FROM ruby:${ruby_version}
4
4
 
5
5
  SHELL ["/bin/bash", "-c"]
6
6
 
7
- RUN gem install bundler -v '~>2.0'
8
-
9
7
  WORKDIR /app
10
8
 
11
- COPY . .
9
+ COPY VERSION Gemfile ezid-client.gemspec ./
12
10
 
13
- RUN bundle install
11
+ RUN gem install bundler -v '~>2.0' && bundle install
12
+
13
+ COPY . .
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.4
1
+ 1.10.0
data/lib/ezid/error.rb CHANGED
@@ -10,4 +10,6 @@ module Ezid
10
10
  class DeletionError < Error; end
11
11
 
12
12
  class UnexpectedResponseError < Error; end
13
+
14
+ class ServerError < Error; end
13
15
  end
@@ -22,6 +22,10 @@ module Ezid
22
22
  POST = Net::HTTP::Post
23
23
  DELETE = Net::HTTP::Delete
24
24
 
25
+ RETRIABLE_SERVER_ERRORS = %w[500 502 503 504].freeze
26
+
27
+ RETRIES = ENV.fetch('EZID_REQUEST_RETRIES', '2').to_i
28
+
25
29
  class << self
26
30
  attr_accessor :http_method, :path, :response_class
27
31
 
@@ -37,7 +41,7 @@ module Ezid
37
41
  end
38
42
 
39
43
  attr_reader :client
40
- def_delegators :client, :connection, :user, :password, :session
44
+ def_delegators :client, :connection, :user, :password, :session, :logger, :config
41
45
 
42
46
  # @param client [Ezid::Client] the client
43
47
  def initialize(client, *args)
@@ -50,12 +54,24 @@ module Ezid
50
54
  # @return [Ezid::Response] the response
51
55
  def execute
52
56
  retries = 0
57
+
53
58
  begin
54
- response_class.new(get_response_for_request)
55
- rescue Net::HTTPServerException, UnexpectedResponseError => e
56
- if retries < 2
57
- sleep client.config.retry_interval
59
+ http_response = get_response_for_request
60
+
61
+ if RETRIABLE_SERVER_ERRORS.include? http_response.code
62
+ raise ServerError, "#{http_response.code} #{http_response.msg}"
63
+ end
64
+
65
+ response_class.new(http_response)
66
+
67
+ rescue ServerError, UnexpectedResponseError => e
68
+ if retries < RETRIES
69
+ logger.error "EZID error: #{e}"
70
+
58
71
  retries += 1
72
+ logger.info "Retry (#{retries} of #{RETRIES}) of #{short_name} #{path} in #{config.retry_interval} seconds ..."
73
+ sleep config.retry_interval
74
+
59
75
  retry
60
76
  else
61
77
  raise
@@ -85,6 +101,10 @@ module Ezid
85
101
  # @return [String] the query string
86
102
  def query; end
87
103
 
104
+ def short_name
105
+ self.class.short_name
106
+ end
107
+
88
108
  def authentication_required?
89
109
  true
90
110
  end
@@ -15,8 +15,6 @@ module Ezid
15
15
  ERROR = "error".freeze
16
16
 
17
17
  def initialize(http_response)
18
- http_response.value # raises Net::HTTPServerException
19
-
20
18
  super
21
19
 
22
20
  unless status_line =~ /^(#{SUCCESS}|#{ERROR}): /
@@ -179,16 +179,6 @@ EOS
179
179
  allow(GetIdentifierMetadataRequest).to receive(:execute).with(subject, "invalid") { stub_response }
180
180
  end
181
181
 
182
- describe "HTTP error response" do
183
- before do
184
- allow(http_response).to receive(:value).and_raise(Net::HTTPServerException.new('Barf!', double))
185
- end
186
-
187
- it "raises an exception" do
188
- expect { subject.get_identifier_metadata("invalid") }.to raise_error(Net::HTTPServerException)
189
- end
190
- end
191
-
192
182
  describe "EZID API error response" do
193
183
  let(:body) { "error: bad request - no such identifier" }
194
184
 
@@ -220,11 +210,12 @@ EOS
220
210
 
221
211
  describe "retrying on certain errors" do
222
212
  before do
213
+ allow(subject.config).to receive(:retry_interval) { 1 }
223
214
  allow(GetIdentifierMetadataResponse).to receive(:new).and_raise(exception)
224
215
  end
225
216
 
226
- describe "HTTP error" do
227
- let(:exception) { Net::HTTPServerException.new('Barf!', double) }
217
+ describe "retriable server error" do
218
+ let(:exception) { ServerError.new('502 Bad Gateway') }
228
219
 
229
220
  it "retries twice" do
230
221
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezid-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.4
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -187,7 +187,7 @@ homepage: https://github.com/duke-libraries/ezid-client
187
187
  licenses:
188
188
  - BSD-3-Clause
189
189
  metadata: {}
190
- post_install_message:
190
+ post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths:
193
193
  - lib
@@ -202,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  requirements: []
205
- rubygems_version: 3.0.3.1
206
- signing_key:
205
+ rubygems_version: 3.5.6
206
+ signing_key:
207
207
  specification_version: 4
208
208
  summary: Ruby client for EZID API Version 2
209
209
  test_files: