relaton 1.11.4 → 1.11.5
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/relaton/db.rb +17 -5
- data/lib/relaton/version.rb +1 -1
- data/spec/relaton/db_spec.rb +16 -0
- 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: 4c30099df631e2cbb313f936f4d6a339d9a0767c6d81f3e9523f6013ce95e77a
|
|
4
|
+
data.tar.gz: 9413dc9a5806d1b7a997c68298029407a5bc5fb0daa92e8c7f19c66b8b285bd3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
100
|
-
|
|
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] << [
|
|
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
|
-
|
|
360
|
-
|
|
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
|
data/lib/relaton/version.rb
CHANGED
data/spec/relaton/db_spec.rb
CHANGED
|
@@ -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
|