relaton 1.9.2 → 1.9.6
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/docs/README.adoc +3 -2
- data/lib/relaton/db.rb +19 -11
- data/lib/relaton/registry.rb +1 -1
- data/lib/relaton/version.rb +1 -1
- data/lib/relaton/workers_pool.rb +3 -3
- data/relaton.gemspec +1 -0
- data/spec/relaton/db_spec.rb +12 -2
- data/spec/relaton/registry_spec.rb +4 -0
- data/spec/relaton_spec.rb +12 -5
- data/spec/vcr_cassetes/async_fetch.yml +1572 -1619
- data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +11 -11
- data/spec/vcr_cassetes/cc_dir_10005_2019.yml +14 -14
- data/spec/vcr_cassetes/cen_en_10160_1999.yml +29 -29
- data/spec/vcr_cassetes/cie_001_1980.yml +7 -7
- data/spec/vcr_cassetes/ecma_6.yml +7 -7
- data/spec/vcr_cassetes/fisp_140.yml +6 -6
- data/spec/vcr_cassetes/gb_t_20223_2006.yml +8 -8
- data/spec/vcr_cassetes/iana_service_names_port_numbers.yml +98 -0
- data/spec/vcr_cassetes/iec_60050_102_2007.yml +28 -28
- data/spec/vcr_cassetes/iec_combined_included.yml +90 -88
- data/spec/vcr_cassetes/ieee_528_2019.yml +14 -14
- data/spec/vcr_cassetes/iho_b_11.yml +7 -7
- data/spec/vcr_cassetes/iso_111111119115_1.yml +2 -2
- data/spec/vcr_cassetes/iso_19115_1.yml +15 -15
- data/spec/vcr_cassetes/iso_19115_1_2.yml +32 -32
- data/spec/vcr_cassetes/iso_19115_all_parts.yml +16 -16
- data/spec/vcr_cassetes/iso_19133_2005.yml +14 -14
- data/spec/vcr_cassetes/iso_cd_14093.yml +15 -15
- data/spec/vcr_cassetes/iso_combined_applied.yml +30 -30
- data/spec/vcr_cassetes/iso_combined_included.yml +32 -32
- data/spec/vcr_cassetes/itu_combined_included.yml +170 -170
- data/spec/vcr_cassetes/ogc_19_025r1.yml +7 -7
- data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +4 -4
- data/spec/vcr_cassetes/rfc_8341.yml +7 -7
- data/spec/vcr_cassetes/sp_800_38b.yml +6 -6
- data/spec/vcr_cassetes/threads_from_env.yml +448 -0
- data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +30 -30
- data/spec/vcr_cassetes/w3c_json_ld11.yml +93 -138
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0856681e37a3dfb7fef7e84084c49990f4f980efcdf2bd3be6e019c9baf8c3e6'
|
|
4
|
+
data.tar.gz: 9c53c38d1b422435f5969ce02f7bee7b05d1195e57b0526a958a83abcaf2eea6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc981fcd5df1fc7de922df2a2e979963d26ef784e4a6bc88448a632a8b09a0483292edbd2ecbe70caa129d59a7c9254c95c9307d01bd5dba6d0e28cd17832fbb
|
|
7
|
+
data.tar.gz: 27cb0dd8f208880222fdc4d8960ef644ca9ec1b1ed678621807ca319fe0596e7a560815c78504b4ebd4de35198f91a054125e5632273a068d44781abfa62a65e
|
data/docs/README.adoc
CHANGED
|
@@ -178,6 +178,7 @@ x = db.fetch_db("ISO 5749")
|
|
|
178
178
|
=> nil
|
|
179
179
|
|
|
180
180
|
# Fetching asynchronously
|
|
181
|
+
# RELATON_FETCH_PARALLEL environment variable can be used to ovveride default number of parallel fetches
|
|
181
182
|
|
|
182
183
|
# prepare queue for results
|
|
183
184
|
results = Queue.new
|
|
@@ -187,8 +188,8 @@ refs = ["ISO 19011", "ISO 19115"]
|
|
|
187
188
|
|
|
188
189
|
# fetch documents
|
|
189
190
|
refs.each do |ref|
|
|
190
|
-
db.fetch_async(ref
|
|
191
|
-
results << [doc,
|
|
191
|
+
db.fetch_async(ref) do |doc|
|
|
192
|
+
results << [doc, ref]
|
|
192
193
|
end
|
|
193
194
|
end
|
|
194
195
|
|
data/lib/relaton/db.rb
CHANGED
|
@@ -17,6 +17,7 @@ module Relaton
|
|
|
17
17
|
@static_db = open_cache_biblio File.expand_path("../relaton/static_cache",
|
|
18
18
|
__dir__)
|
|
19
19
|
@queues = {}
|
|
20
|
+
@semaphore = Mutex.new
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
# Move global or local caches to anothe dirs
|
|
@@ -99,20 +100,21 @@ module Relaton
|
|
|
99
100
|
end
|
|
100
101
|
|
|
101
102
|
# Fetch asynchronously
|
|
102
|
-
def fetch_async(code, year = nil, opts = {},
|
|
103
|
+
def fetch_async(code, year = nil, opts = {}, &block) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
|
103
104
|
stdclass = standard_class code
|
|
104
105
|
if stdclass
|
|
105
106
|
unless @queues[stdclass]
|
|
106
107
|
processor = @registry.processors[stdclass]
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
threads = ENV["RELATON_FETCH_PARALLEL"]&.to_i || processor.threads
|
|
109
|
+
wp = WorkersPool.new(threads) do |args|
|
|
110
|
+
args[3].call fetch(*args[0..2])
|
|
109
111
|
rescue RelatonBib::RequestError => e
|
|
110
|
-
|
|
112
|
+
args[3].call e
|
|
111
113
|
end
|
|
112
114
|
@queues[stdclass] = { queue: Queue.new, workers_pool: wp }
|
|
113
115
|
Thread.new { process_queue @queues[stdclass] }
|
|
114
116
|
end
|
|
115
|
-
@queues[stdclass][:queue] << [code, year, opts,
|
|
117
|
+
@queues[stdclass][:queue] << [code, year, opts, block]
|
|
116
118
|
else yield nil
|
|
117
119
|
end
|
|
118
120
|
end
|
|
@@ -375,14 +377,20 @@ module Relaton
|
|
|
375
377
|
return bib_retval(bibentry, stdclass)
|
|
376
378
|
end
|
|
377
379
|
|
|
378
|
-
|
|
380
|
+
@semaphore.synchronize do
|
|
381
|
+
db.delete(id) unless db.valid_entry?(id, year)
|
|
382
|
+
end
|
|
379
383
|
if altdb
|
|
380
384
|
return bib_retval(altdb[id], stdclass) if opts[:fetch_db]
|
|
381
385
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
+
@semaphore.synchronize do
|
|
387
|
+
db.clone_entry id, altdb if altdb.valid_entry? id, year
|
|
388
|
+
end
|
|
389
|
+
entry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id) unless db[id]
|
|
390
|
+
@semaphore.synchronize do
|
|
391
|
+
db[id] ||= entry
|
|
392
|
+
altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
|
|
393
|
+
end
|
|
386
394
|
else
|
|
387
395
|
return bib_retval(db[id], stdclass) if opts[:fetch_db]
|
|
388
396
|
|
|
@@ -413,7 +421,7 @@ module Relaton
|
|
|
413
421
|
if args[:db] && args[:id] &&
|
|
414
422
|
bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
|
|
415
423
|
bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
|
|
416
|
-
args[:db][bid] ||= bib_entry bib
|
|
424
|
+
@semaphore.synchronize { args[:db][bid] ||= bib_entry bib }
|
|
417
425
|
"redirection #{bid}"
|
|
418
426
|
else bib_entry bib
|
|
419
427
|
end
|
data/lib/relaton/registry.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Relaton
|
|
|
9
9
|
relaton_gb relaton_iec relaton_ietf relaton_iso relaton_itu relaton_nist
|
|
10
10
|
relaton_ogc relaton_calconnect relaton_omg relaton_un relaton_w3c
|
|
11
11
|
relaton_ieee relaton_iho relaton_bipm relaton_ecma relaton_cie relaton_bsi
|
|
12
|
-
relaton_cen
|
|
12
|
+
relaton_cen relaton_iana
|
|
13
13
|
].freeze
|
|
14
14
|
|
|
15
15
|
include Singleton
|
data/lib/relaton/version.rb
CHANGED
data/lib/relaton/workers_pool.rb
CHANGED
|
@@ -4,9 +4,9 @@ module Relaton
|
|
|
4
4
|
# Workers poll.
|
|
5
5
|
class WorkersPool
|
|
6
6
|
def initialize(workers = 2, &_block)
|
|
7
|
-
num_workers = workers < 2 ? 2 : workers
|
|
8
|
-
@queue = SizedQueue.new(
|
|
9
|
-
@threads = Array.new
|
|
7
|
+
# num_workers = workers < 2 ? 2 : workers
|
|
8
|
+
@queue = SizedQueue.new(workers * 2)
|
|
9
|
+
@threads = Array.new workers do
|
|
10
10
|
Thread.new do
|
|
11
11
|
while item = @queue.pop; yield(item) end
|
|
12
12
|
end
|
data/relaton.gemspec
CHANGED
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
|
36
36
|
spec.add_dependency "relaton-cie", "~> 1.9.0"
|
|
37
37
|
spec.add_dependency "relaton-ecma", "~> 1.9.0"
|
|
38
38
|
spec.add_dependency "relaton-gb", "~> 1.9.0"
|
|
39
|
+
spec.add_dependency "relaton-iana", "~> 1.9.0"
|
|
39
40
|
spec.add_dependency "relaton-iec", "~> 1.9.0"
|
|
40
41
|
spec.add_dependency "relaton-ieee", "~> 1.9.0"
|
|
41
42
|
spec.add_dependency "relaton-ietf", "~> 1.9.0"
|
data/spec/relaton/db_spec.rb
CHANGED
|
@@ -163,8 +163,8 @@ RSpec.describe Relaton::Db do
|
|
|
163
163
|
results = []
|
|
164
164
|
VCR.use_cassette "async_fetch", match_requests_on: %i[method uri body] do
|
|
165
165
|
refs.each do |ref|
|
|
166
|
-
db.fetch_async(ref
|
|
167
|
-
queue << [r,
|
|
166
|
+
db.fetch_async(ref) do |r|
|
|
167
|
+
queue << [r, ref]
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
Timeout.timeout(60) do
|
|
@@ -184,6 +184,16 @@ RSpec.describe Relaton::Db do
|
|
|
184
184
|
end
|
|
185
185
|
expect(result).to be_nil
|
|
186
186
|
end
|
|
187
|
+
|
|
188
|
+
it "use threads number from RELATON_FETCH_PARALLEL" do
|
|
189
|
+
expect(ENV).to receive(:[]).with("RELATON_FETCH_PARALLEL").and_return(1)
|
|
190
|
+
allow(ENV).to receive(:[]).and_call_original
|
|
191
|
+
expect(Relaton::WorkersPool).to receive(:new).with(1).and_call_original
|
|
192
|
+
VCR.use_cassette "threads_from_env" do
|
|
193
|
+
db.fetch_async("ITU-T G.993.5") { |r| queue << r }
|
|
194
|
+
Timeout.timeout(5) { queue.pop }
|
|
195
|
+
end
|
|
196
|
+
end
|
|
187
197
|
end
|
|
188
198
|
|
|
189
199
|
context "fetch documents form static cache" do
|
|
@@ -87,6 +87,10 @@ RSpec.describe Relaton::Registry do
|
|
|
87
87
|
it "CEN" do
|
|
88
88
|
expect(Relaton::Registry.instance.by_type("CEN")).to be_instance_of RelatonCen::Processor
|
|
89
89
|
end
|
|
90
|
+
|
|
91
|
+
it "IANA" do
|
|
92
|
+
expect(Relaton::Registry.instance.by_type("IANA")).to be_instance_of RelatonIana::Processor
|
|
93
|
+
end
|
|
90
94
|
end
|
|
91
95
|
|
|
92
96
|
it "find processot by dataset" do
|
data/spec/relaton_spec.rb
CHANGED
|
@@ -246,13 +246,13 @@ RSpec.describe Relaton::Db do
|
|
|
246
246
|
end
|
|
247
247
|
|
|
248
248
|
it "get W3C reference" do
|
|
249
|
-
w3c_fr = /\.relaton\/w3c\/bibliography\.yml/
|
|
250
|
-
expect(File).to receive(:exist?).with(w3c_fr).and_return false
|
|
251
|
-
expect(File).to receive(:exist?).and_call_original.at_least :once
|
|
252
|
-
expect(File).to receive(:write).with w3c_fr, kind_of(String), kind_of(Hash)
|
|
249
|
+
# w3c_fr = /\.relaton\/w3c\/bibliography\.yml/
|
|
250
|
+
# expect(File).to receive(:exist?).with(w3c_fr).and_return false
|
|
251
|
+
# expect(File).to receive(:exist?).and_call_original.at_least :once
|
|
252
|
+
# expect(File).to receive(:write).with w3c_fr, kind_of(String), kind_of(Hash)
|
|
253
253
|
# expect(File).to receive(:write).and_call_original.at_least :once
|
|
254
254
|
VCR.use_cassette "w3c_json_ld11" do
|
|
255
|
-
bib = @db.fetch "W3C
|
|
255
|
+
bib = @db.fetch "W3C REC-json-ld11-20200716", nil, {}
|
|
256
256
|
expect(bib).to be_instance_of RelatonW3c::W3cBibliographicItem
|
|
257
257
|
end
|
|
258
258
|
end
|
|
@@ -299,6 +299,13 @@ RSpec.describe Relaton::Db do
|
|
|
299
299
|
end
|
|
300
300
|
end
|
|
301
301
|
|
|
302
|
+
it "get IANA reference" do
|
|
303
|
+
VCR.use_cassette "iana_service_names_port_numbers" do
|
|
304
|
+
bib = @db.fetch "IANA service-names-port-numbers"
|
|
305
|
+
expect(bib).to be_instance_of RelatonBib::BibliographicItem
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
302
309
|
context "get combined documents" do
|
|
303
310
|
context "ISO" do
|
|
304
311
|
it "included" do
|