baza.rb 0.9.5 → 0.9.7
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/.github/workflows/typos.yml +1 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +14 -7
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +8 -5
- data/test/test_baza-rb.rb +15 -26
- 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: b4291b734210c6b32949c0025f343304de1c636ab00e0d2efdaeaf8e9eba3a51
|
4
|
+
data.tar.gz: d3cd7f75b3d71a17dea16c1cd164d094c8b4c26b1a20e56c62df8c0d5778f80a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6375cc3204a5530b8c1b90c8376a63ce262c51cf0ef9ce998068c467390cd94d911c5be0ab16c5bb43522eddabb24b3af8e0de7261ad28baebfdea074d589bd
|
7
|
+
data.tar.gz: 2fcbdcd001c5dc9d1c26320583c6f4a09debc1bbf89b461f0964abcbe4fc165ce7a1f98844c31f7fdeaea076d8c3383308cfc160850a5cde8acebbc28cadbe18
|
data/.github/workflows/typos.yml
CHANGED
data/Gemfile
CHANGED
@@ -10,6 +10,8 @@ gem 'base64', '~>0.3', require: false
|
|
10
10
|
gem 'factbase', '~>0.11', require: false
|
11
11
|
gem 'minitest', '~>5.25', require: false
|
12
12
|
gem 'minitest-reporters', '~>1.7', require: false
|
13
|
+
gem 'nio4r', '2.7.4', require: false # GPL
|
14
|
+
gem 'online', '~>0.0', require: false
|
13
15
|
gem 'os', '~>1.1', require: false
|
14
16
|
gem 'puma', '~>6.6', require: false
|
15
17
|
gem 'qbash', '~>0.4', require: false
|
@@ -24,7 +26,7 @@ gem 'rubocop-rake', '~>0.7', require: false
|
|
24
26
|
gem 'simplecov', '~>0.22', require: false
|
25
27
|
gem 'simplecov-cobertura', '~>2.1', require: false
|
26
28
|
gem 'sinatra', '~>4.1', require: false
|
27
|
-
gem 'wait_for', '
|
29
|
+
gem 'wait_for', '0.1.1', require: false # Unlicensed
|
28
30
|
gem 'webmock', '~>3.24', require: false
|
29
31
|
gem 'webrick', '~>1.9', require: false
|
30
32
|
gem 'yard', '~>0.9', require: false
|
data/Gemfile.lock
CHANGED
@@ -28,16 +28,18 @@ GEM
|
|
28
28
|
crack (1.0.0)
|
29
29
|
bigdecimal
|
30
30
|
rexml
|
31
|
-
decoor (0.0
|
31
|
+
decoor (0.1.0)
|
32
32
|
docile (1.4.1)
|
33
|
-
elapsed (0.0
|
33
|
+
elapsed (0.1.0)
|
34
34
|
loog (> 0)
|
35
35
|
tago (> 0)
|
36
|
+
ellipsized (0.3.0)
|
36
37
|
ethon (0.16.0)
|
37
38
|
ffi (>= 1.15.0)
|
38
|
-
factbase (0.
|
39
|
+
factbase (0.12.1)
|
39
40
|
backtrace (~> 0.4)
|
40
41
|
decoor (~> 0.0)
|
42
|
+
ellipsized (~> 0.3)
|
41
43
|
json (~> 2.7)
|
42
44
|
logger (~> 1.0)
|
43
45
|
loog (~> 0.6)
|
@@ -55,7 +57,7 @@ GEM
|
|
55
57
|
multipart-post (~> 2.0)
|
56
58
|
faraday-net_http (3.4.1)
|
57
59
|
net-http (>= 0.5.0)
|
58
|
-
faraday-retry (2.3.
|
60
|
+
faraday-retry (2.3.2)
|
59
61
|
faraday (~> 2.0)
|
60
62
|
ffi (1.17.2-arm64-darwin)
|
61
63
|
ffi (1.17.2-x64-mingw-ucrt)
|
@@ -89,8 +91,10 @@ GEM
|
|
89
91
|
racc (~> 1.4)
|
90
92
|
nokogiri (1.18.8-x86_64-linux-gnu)
|
91
93
|
racc (~> 1.4)
|
94
|
+
online (0.0.1)
|
95
|
+
timeout (~> 0.4)
|
92
96
|
os (1.1.4)
|
93
|
-
others (0.
|
97
|
+
others (0.1.1)
|
94
98
|
parallel (1.27.0)
|
95
99
|
parser (3.3.8.0)
|
96
100
|
ast (~> 2.4.1)
|
@@ -122,7 +126,7 @@ GEM
|
|
122
126
|
regexp_parser (2.10.0)
|
123
127
|
retries (0.0.5)
|
124
128
|
rexml (3.4.1)
|
125
|
-
rubocop (1.
|
129
|
+
rubocop (1.77.0)
|
126
130
|
json (~> 2.3)
|
127
131
|
language_server-protocol (~> 3.17.0.2)
|
128
132
|
lint_roller (~> 1.1.0)
|
@@ -167,6 +171,7 @@ GEM
|
|
167
171
|
tilt (~> 2.0)
|
168
172
|
tago (0.1.0)
|
169
173
|
tilt (2.6.0)
|
174
|
+
timeout (0.4.3)
|
170
175
|
typhoeus (1.4.1)
|
171
176
|
ethon (>= 0.9.0)
|
172
177
|
unicode-display_width (3.1.4)
|
@@ -197,6 +202,8 @@ DEPENDENCIES
|
|
197
202
|
factbase (~> 0.11)
|
198
203
|
minitest (~> 5.25)
|
199
204
|
minitest-reporters (~> 1.7)
|
205
|
+
nio4r (= 2.7.4)
|
206
|
+
online (~> 0.0)
|
200
207
|
os (~> 1.1)
|
201
208
|
puma (~> 6.6)
|
202
209
|
qbash (~> 0.4)
|
@@ -211,7 +218,7 @@ DEPENDENCIES
|
|
211
218
|
simplecov (~> 0.22)
|
212
219
|
simplecov-cobertura (~> 2.1)
|
213
220
|
sinatra (~> 4.1)
|
214
|
-
wait_for (
|
221
|
+
wait_for (= 0.1.1)
|
215
222
|
webmock (~> 3.24)
|
216
223
|
webrick (~> 1.9)
|
217
224
|
yard (~> 0.9)
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
@@ -31,6 +31,9 @@ require_relative 'baza-rb/version'
|
|
31
31
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class BazaRb
|
34
|
+
# How big are the chunks we send, by default, in bytes:
|
35
|
+
DEFAULT_CHUNK_SIZE = 4_000_000
|
36
|
+
|
34
37
|
# When the server failed (503).
|
35
38
|
class ServerFailure < StandardError; end
|
36
39
|
|
@@ -99,7 +102,7 @@ class BazaRb
|
|
99
102
|
# @param [Array<String>] meta List of metadata strings to attach to the job
|
100
103
|
# @param [Integer] chunk_size Maximum size of one chunk
|
101
104
|
# @raise [ServerFailure] If the push operation fails
|
102
|
-
def push(name, data, meta, chunk_size:
|
105
|
+
def push(name, data, meta, chunk_size: DEFAULT_CHUNK_SIZE)
|
103
106
|
raise 'The "name" of the job is nil' if name.nil?
|
104
107
|
raise 'The "name" of the job may not be empty' if name.empty?
|
105
108
|
raise 'The "data" of the job is nil' if data.nil?
|
@@ -287,7 +290,7 @@ class BazaRb
|
|
287
290
|
# @param [Integer] chunk_size Maximum size of one chunk
|
288
291
|
# @return [Integer] The ID of the created durable
|
289
292
|
# @raise [ServerFailure] If the upload fails
|
290
|
-
def durable_place(jname, file, chunk_size:
|
293
|
+
def durable_place(jname, file, chunk_size: DEFAULT_CHUNK_SIZE)
|
291
294
|
raise 'The "jname" of the durable is nil' if jname.nil?
|
292
295
|
raise 'The "jname" of the durable may not be empty' if jname.empty?
|
293
296
|
raise 'The "file" of the durable is nil' if file.nil?
|
@@ -320,7 +323,7 @@ class BazaRb
|
|
320
323
|
# @param [String] file The file to upload
|
321
324
|
# @param [Integer] chunk_size Maximum size of one chunk
|
322
325
|
# @raise [ServerFailure] If the save operation fails
|
323
|
-
def durable_save(id, file, chunk_size:
|
326
|
+
def durable_save(id, file, chunk_size: DEFAULT_CHUNK_SIZE)
|
324
327
|
raise 'The ID of the durable is nil' if id.nil?
|
325
328
|
raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
|
326
329
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
@@ -529,7 +532,7 @@ class BazaRb
|
|
529
532
|
# @return [String] The cached result or newly computed result from the block
|
530
533
|
# @raise [ServerFailure] If the valve operation fails
|
531
534
|
def enter(name, badge, why, job)
|
532
|
-
elapsed(@loog,
|
535
|
+
elapsed(@loog, good: "Entered valve #{badge} to #{name}") do
|
533
536
|
retry_it do
|
534
537
|
ret = get(home.append('valves').append('result').add(badge:), [200, 204])
|
535
538
|
return ret.body if ret.code == 200
|
@@ -803,7 +806,7 @@ class BazaRb
|
|
803
806
|
# @param [Hash] extra Hash of extra HTTP headers to include
|
804
807
|
# @param [Integer] chunk_size Maximum size of each chunk in bytes
|
805
808
|
# @raise [ServerFailure] If the upload fails
|
806
|
-
def upload(uri, file, extra = {}, chunk_size:
|
809
|
+
def upload(uri, file, extra = {}, chunk_size: DEFAULT_CHUNK_SIZE)
|
807
810
|
params = {
|
808
811
|
connecttimeout: @timeout,
|
809
812
|
timeout: @timeout,
|
data/test/test_baza-rb.rb
CHANGED
@@ -7,6 +7,7 @@ require 'factbase'
|
|
7
7
|
require 'loog'
|
8
8
|
require 'net/http'
|
9
9
|
require 'qbash'
|
10
|
+
require 'online'
|
10
11
|
require 'random-port'
|
11
12
|
require 'securerandom'
|
12
13
|
require 'socket'
|
@@ -36,7 +37,7 @@ class TestBazaRb < Minitest::Test
|
|
36
37
|
|
37
38
|
def test_live_full_cycle
|
38
39
|
WebMock.enable_net_connect!
|
39
|
-
skip('We are offline') unless we_are_online
|
40
|
+
skip('We are offline') unless we_are_online?
|
40
41
|
fb = Factbase.new
|
41
42
|
fb.insert.foo = 'test-' * 10_000
|
42
43
|
fb.insert
|
@@ -62,13 +63,13 @@ class TestBazaRb < Minitest::Test
|
|
62
63
|
|
63
64
|
def test_live_whoami
|
64
65
|
WebMock.enable_net_connect!
|
65
|
-
skip('We are offline') unless we_are_online
|
66
|
+
skip('We are offline') unless we_are_online?
|
66
67
|
refute_nil(LIVE.whoami)
|
67
68
|
end
|
68
69
|
|
69
70
|
def test_live_balance
|
70
71
|
WebMock.enable_net_connect!
|
71
|
-
skip('We are offline') unless we_are_online
|
72
|
+
skip('We are offline') unless we_are_online?
|
72
73
|
z = LIVE.balance
|
73
74
|
refute_nil(z)
|
74
75
|
assert(z.to_f)
|
@@ -76,13 +77,13 @@ class TestBazaRb < Minitest::Test
|
|
76
77
|
|
77
78
|
def test_live_fee_payment
|
78
79
|
WebMock.enable_net_connect!
|
79
|
-
skip('We are offline') unless we_are_online
|
80
|
+
skip('We are offline') unless we_are_online?
|
80
81
|
refute_nil(LIVE.fee('unknown', 0.007, 'just for fun', 777))
|
81
82
|
end
|
82
83
|
|
83
84
|
def test_live_push_no_compression
|
84
85
|
WebMock.enable_net_connect!
|
85
|
-
skip('We are offline') unless we_are_online
|
86
|
+
skip('We are offline') unless we_are_online?
|
86
87
|
fb = Factbase.new
|
87
88
|
fb.insert.foo = 'test-' * 10_000
|
88
89
|
fb.insert
|
@@ -92,7 +93,7 @@ class TestBazaRb < Minitest::Test
|
|
92
93
|
|
93
94
|
def test_live_durable_lock_unlock
|
94
95
|
WebMock.enable_net_connect!
|
95
|
-
skip('We are offline') unless we_are_online
|
96
|
+
skip('We are offline') unless we_are_online?
|
96
97
|
Dir.mktmpdir do |dir|
|
97
98
|
file = File.join(dir, 'before.bin')
|
98
99
|
before = 'hello, Джеф!' * 10
|
@@ -116,7 +117,7 @@ class TestBazaRb < Minitest::Test
|
|
116
117
|
|
117
118
|
def test_live_enter_valve
|
118
119
|
WebMock.enable_net_connect!
|
119
|
-
skip('We are offline') unless we_are_online
|
120
|
+
skip('We are offline') unless we_are_online?
|
120
121
|
r = 'something'
|
121
122
|
n = fake_name
|
122
123
|
badge = fake_name
|
@@ -126,7 +127,7 @@ class TestBazaRb < Minitest::Test
|
|
126
127
|
|
127
128
|
def test_get_csrf_token
|
128
129
|
WebMock.enable_net_connect!
|
129
|
-
skip('We are offline') unless we_are_online
|
130
|
+
skip('We are offline') unless we_are_online?
|
130
131
|
assert_operator(LIVE.csrf.length, :>, 10)
|
131
132
|
end
|
132
133
|
|
@@ -367,7 +368,7 @@ class TestBazaRb < Minitest::Test
|
|
367
368
|
|
368
369
|
def test_real_http
|
369
370
|
WebMock.enable_net_connect!
|
370
|
-
skip('We are offline') unless we_are_online
|
371
|
+
skip('We are offline') unless we_are_online?
|
371
372
|
req =
|
372
373
|
with_http_server(200, 'yes') do |baza|
|
373
374
|
baza.name_exists?('simple')
|
@@ -377,7 +378,7 @@ class TestBazaRb < Minitest::Test
|
|
377
378
|
|
378
379
|
def test_push_with_meta
|
379
380
|
WebMock.enable_net_connect!
|
380
|
-
skip('We are offline') unless we_are_online
|
381
|
+
skip('We are offline') unless we_are_online?
|
381
382
|
req =
|
382
383
|
with_http_server(200, 'yes') do |baza|
|
383
384
|
baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
|
@@ -387,7 +388,7 @@ class TestBazaRb < Minitest::Test
|
|
387
388
|
|
388
389
|
def test_push_with_big_meta
|
389
390
|
WebMock.enable_net_connect!
|
390
|
-
skip('We are offline') unless we_are_online
|
391
|
+
skip('We are offline') unless we_are_online?
|
391
392
|
req =
|
392
393
|
with_http_server(200, 'yes') do |baza|
|
393
394
|
baza.push(
|
@@ -405,7 +406,7 @@ class TestBazaRb < Minitest::Test
|
|
405
406
|
|
406
407
|
def test_push_compressed_content
|
407
408
|
WebMock.enable_net_connect!
|
408
|
-
skip('We are offline') unless we_are_online
|
409
|
+
skip('We are offline') unless we_are_online?
|
409
410
|
fb = Factbase.new
|
410
411
|
fb.insert.foo = 'test-' * 10_000
|
411
412
|
req =
|
@@ -770,20 +771,8 @@ class TestBazaRb < Minitest::Test
|
|
770
771
|
"fake#{SecureRandom.hex(8)}"
|
771
772
|
end
|
772
773
|
|
773
|
-
def we_are_online
|
774
|
-
$we_are_online ||= !ARGV.include?('--offline') &&
|
774
|
+
def we_are_online?
|
775
|
+
$we_are_online ||= !ARGV.include?('--offline') && online?
|
775
776
|
end
|
776
777
|
# rubocop:enable Style/GlobalVars
|
777
|
-
|
778
|
-
# Checks whether this URI is alive (HTTP status is 200).
|
779
|
-
def uri_is_alive(uri)
|
780
|
-
Timeout.timeout(4) do
|
781
|
-
require 'net/http'
|
782
|
-
WebMock.enable_net_connect!
|
783
|
-
Net::HTTP.get_response(URI(uri)).is_a?(Net::HTTPSuccess)
|
784
|
-
rescue Timeout::Error, Timeout::ExitException, Socket::ResolutionError, Errno::EHOSTUNREACH, Errno::EINVAL
|
785
|
-
puts "Ping failed to #{uri}"
|
786
|
-
false
|
787
|
-
end
|
788
|
-
end
|
789
778
|
end
|