relaton 1.11.4 → 1.11.5

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: bd53313a7d35f6ed1adf7669962afc84282d15d232247d3facec910aaba05270
4
- data.tar.gz: 304a0e1c5a44731f0a4f9a30c063df920deb8694aca702044fd1ab03a10fe5e8
3
+ metadata.gz: 4c30099df631e2cbb313f936f4d6a339d9a0767c6d81f3e9523f6013ce95e77a
4
+ data.tar.gz: 9413dc9a5806d1b7a997c68298029407a5bc5fb0daa92e8c7f19c66b8b285bd3
5
5
  SHA512:
6
- metadata.gz: 4cfb3d708769580fccb31ef09a408265a4b828e70082c7f44a2fe485c2982437cf4f8b8369ada51e7e2d9d3e05c05eada5eaca8126506ea5b9224b7575727501
7
- data.tar.gz: 2255f0695f06f0714e55b03d9a9ad7c2b7567d417ff184e598c462e299aeed145fb6fb143fc9e83aedf7223479addd9542a6ea3d16b17298f55621676100010f
6
+ metadata.gz: 33f734e4a386c381de112a99f649c54a586c1367cf91065a693235c8c7252a414a38bffa589de960c3cb4564ab08a0311557c38e08804566ac06a8baf6207de7
7
+ data.tar.gz: d0e46c2f6ad5ac0263de42c693db297786b583da4a9b86fe2f3db9f2807e6fdd98c9934ff892d362f1e6a53f2c6cf9a8856b66f405b7fc8270c99f198b9a46b3
data/lib/relaton/db.rb CHANGED
@@ -95,9 +95,18 @@ module Relaton
95
95
  result
96
96
  end
97
97
 
98
+ #
98
99
  # Fetch asynchronously
99
- def fetch_async(code, year = nil, opts = {}, &block) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
100
- stdclass = @registry.class_by_ref code
100
+ #
101
+ # @param [String] ref reference
102
+ # @param [String] year document yer
103
+ # @param [Hash] opts options
104
+ #
105
+ # @return [RelatonBib::BibliographicItem, RelatonBib::RequestError, nil] bibitem if document is found,
106
+ # request error if server doesn't answer, nil if document not found
107
+ #
108
+ def fetch_async(ref, year = nil, opts = {}, &block) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
109
+ stdclass = @registry.class_by_ref ref
101
110
  if stdclass
102
111
  unless @queues[stdclass]
103
112
  processor = @registry.processors[stdclass]
@@ -106,11 +115,14 @@ module Relaton
106
115
  args[3].call fetch(*args[0..2])
107
116
  rescue RelatonBib::RequestError => e
108
117
  args[3].call e
118
+ rescue StandardError => e
119
+ Util.log "[relaton] ERROR: #{args[0]} -- #{e.message}", :error
120
+ args[3].call nil
109
121
  end
110
122
  @queues[stdclass] = { queue: Queue.new, workers_pool: wp }
111
123
  Thread.new { process_queue @queues[stdclass] }
112
124
  end
113
- @queues[stdclass][:queue] << [code, year, opts, block]
125
+ @queues[stdclass][:queue] << [ref, year, opts, block]
114
126
  else yield nil
115
127
  end
116
128
  end
@@ -356,8 +368,8 @@ module Relaton
356
368
  else
357
369
  return bib_retval(db[id], stdclass) if opts[:fetch_db]
358
370
 
359
- db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
360
- id: id)
371
+ entry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id) unless db[id]
372
+ @semaphore.synchronize { db[id] ||= entry }
361
373
  end
362
374
  bib_retval(db[id], stdclass)
363
375
  end
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.11.4".freeze
2
+ VERSION = "1.11.5".freeze
3
3
  end
@@ -198,6 +198,22 @@ RSpec.describe Relaton::Db do
198
198
  expect(result).to be_nil
199
199
  end
200
200
 
201
+ it "handle HTTP request error" do
202
+ expect(db).to receive(:fetch).and_raise RelatonBib::RequestError
203
+ db.fetch_async("ISO REF") { |r| queue << r }
204
+ result = Timeout.timeout(5) { queue.pop }
205
+ expect(result).to be_instance_of RelatonBib::RequestError
206
+ end
207
+
208
+ it "handle other errors" do
209
+ expect(db).to receive(:fetch).and_raise Errno::EACCES
210
+ expect do
211
+ db.fetch_async("ISO REF") { |r| queue << r }
212
+ result = Timeout.timeout(5) { queue.pop }
213
+ expect(result).to be_nil
214
+ end.to output("[relaton] ERROR: ISO REF -- Permission denied\n").to_stderr
215
+ end
216
+
201
217
  it "use threads number from RELATON_FETCH_PARALLEL" do
202
218
  expect(ENV).to receive(:[]).with("RELATON_FETCH_PARALLEL").and_return(1)
203
219
  allow(ENV).to receive(:[]).and_call_original
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.4
4
+ version: 1.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.