baza.rb 0.5.0 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4fb6929da01d8ec60b802d9bd8c3300456ff66144723496bbe60a11b1f67fad
4
- data.tar.gz: 29db7120d95c442fcb529e9f1f1d8f3c7145baca1cf829cd011bdf6b6d6918bd
3
+ metadata.gz: 055d08eba666af0bcadcea162c8b47ccbdd7b9ffc1647830999112a503ad8907
4
+ data.tar.gz: 966991989ab8c9fc2dba9f2c2498a38278a8d70195742266d452c34af33328fb
5
5
  SHA512:
6
- metadata.gz: 0212eb14782da74ea7ecbfa855e3a075e4639577f512ea12f98549451a7000a820a0bbb918f909f0eacde8c62593bc62910b7829a759ee989a2844e5def8fb20
7
- data.tar.gz: 883fb08a189555e8abdb1800c2ab2d08229833945b11809930412d5da82890b23856122c9e2fe6c44f369db007a0dee4ebb3b51991a7ba4eedca261ec135b934
6
+ metadata.gz: e699824b88910aa69f738e3329b62b9aece6b296f1e7aec9917b44044b32e14845f1700d774fb4386977fe64a03fcb5bd5e39c15ea4c40053d814a632b95d1ea
7
+ data.tar.gz: f462b2fcada287d6f6af5f6d11bad0651cfbad83b079957a43fcac92cf8947c479be776c73c8346281e82c78803782c44919d8c19ef38670db344435365b15b8
@@ -16,4 +16,4 @@ jobs:
16
16
  runs-on: ubuntu-24.04
17
17
  steps:
18
18
  - uses: actions/checkout@v4
19
- - uses: yegor256/copyrights-action@0.0.10
19
+ - uses: yegor256/copyrights-action@0.0.12
@@ -12,6 +12,7 @@ name: rake
12
12
  - master
13
13
  jobs:
14
14
  rake:
15
+ timeout-minutes: 15
15
16
  strategy:
16
17
  matrix:
17
18
  os: [ubuntu-24.04, macos-15]
@@ -16,4 +16,4 @@ jobs:
16
16
  runs-on: ubuntu-24.04
17
17
  steps:
18
18
  - uses: actions/checkout@v4
19
- - uses: crate-ci/typos@v1.32.0
19
+ - uses: crate-ci/typos@v1.33.1
data/.gitignore CHANGED
@@ -8,4 +8,4 @@ doc/
8
8
  node_modules/
9
9
  rdoc/
10
10
  vendor/
11
- .claude
11
+ .claude/
data/Gemfile CHANGED
@@ -6,21 +6,21 @@
6
6
  source 'https://rubygems.org'
7
7
  gemspec
8
8
 
9
- gem 'base64', '>0', require: false
10
- gem 'factbase', '>0', require: false
9
+ gem 'base64', '~>0.3', require: false
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 'os', '>0', require: false
14
- gem 'qbash', '>0', require: false
13
+ gem 'os', '~>1.1', require: false
14
+ gem 'qbash', '~>0.4', require: false
15
15
  gem 'rake', '~>13.2', require: false
16
- gem 'random-port', '>0', require: false
16
+ gem 'random-port', '~>0.7', require: false
17
17
  gem 'rubocop', '~>1.73', require: false
18
- gem 'rubocop-minitest', '>0', require: false
18
+ gem 'rubocop-minitest', '~>0.38', require: false
19
19
  gem 'rubocop-performance', '~>1.23', require: false
20
- gem 'rubocop-rake', '>0', require: false
20
+ gem 'rubocop-rake', '~>0.7', require: false
21
21
  gem 'simplecov', '~>0.22', require: false
22
22
  gem 'simplecov-cobertura', '~>2.1', require: false
23
- gem 'wait_for', '~>0', require: false
23
+ gem 'wait_for', '~>0.1', require: false
24
24
  gem 'webmock', '~>3.24', require: false
25
25
  gem 'webrick', '~>1.9', require: false
26
26
  gem 'yard', '~>0.9', require: false
data/Gemfile.lock CHANGED
@@ -2,17 +2,17 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  baza.rb (0.0.0)
5
- backtrace (> 0)
6
- elapsed (> 0)
7
- faraday (> 0)
8
- faraday-http-cache (> 0)
9
- faraday-multipart (> 0)
10
- faraday-retry (> 0)
11
- iri (> 0)
12
- loog (> 0)
13
- retries (~> 0)
14
- tago (~> 0)
15
- typhoeus (~> 1.3)
5
+ backtrace (~> 0.4)
6
+ elapsed (~> 0.0)
7
+ faraday (~> 2.13)
8
+ faraday-http-cache (~> 2.5)
9
+ faraday-multipart (~> 1.1)
10
+ faraday-retry (~> 2.3)
11
+ iri (~> 0.11)
12
+ loog (~> 0.6)
13
+ retries (~> 0.0)
14
+ tago (~> 0.0)
15
+ typhoeus (~> 1.4)
16
16
 
17
17
  GEM
18
18
  remote: https://rubygems.org/
@@ -21,9 +21,9 @@ GEM
21
21
  public_suffix (>= 2.0.2, < 7.0)
22
22
  ansi (1.5.0)
23
23
  ast (2.4.3)
24
- backtrace (0.4.0)
25
- base64 (0.2.0)
26
- bigdecimal (3.1.9)
24
+ backtrace (0.4.1)
25
+ base64 (0.3.0)
26
+ bigdecimal (3.2.2)
27
27
  builder (3.3.0)
28
28
  crack (1.0.0)
29
29
  bigdecimal
@@ -35,7 +35,7 @@ GEM
35
35
  tago (> 0)
36
36
  ethon (0.16.0)
37
37
  ffi (>= 1.15.0)
38
- factbase (0.10.2)
38
+ factbase (0.11.0)
39
39
  backtrace (~> 0.4)
40
40
  decoor (~> 0.0)
41
41
  json (~> 2.7)
@@ -62,7 +62,7 @@ GEM
62
62
  ffi (1.17.2-x86_64-darwin)
63
63
  ffi (1.17.2-x86_64-linux-gnu)
64
64
  hashdiff (1.2.0)
65
- iri (0.10.0)
65
+ iri (0.11.2)
66
66
  json (2.12.2)
67
67
  language_server-protocol (3.17.0.5)
68
68
  lint_roller (1.1.0)
@@ -101,13 +101,13 @@ GEM
101
101
  tago (> 0)
102
102
  racc (1.8.1)
103
103
  rainbow (3.1.1)
104
- rake (13.2.1)
104
+ rake (13.3.0)
105
105
  random-port (0.7.5)
106
106
  tago (> 0)
107
107
  regexp_parser (2.10.0)
108
108
  retries (0.0.5)
109
109
  rexml (3.4.1)
110
- rubocop (1.75.7)
110
+ rubocop (1.76.0)
111
111
  json (~> 2.3)
112
112
  language_server-protocol (~> 3.17.0.2)
113
113
  lint_roller (~> 1.1.0)
@@ -115,13 +115,13 @@ GEM
115
115
  parser (>= 3.3.0.2)
116
116
  rainbow (>= 2.2.2, < 4.0)
117
117
  regexp_parser (>= 2.9.3, < 3.0)
118
- rubocop-ast (>= 1.44.0, < 2.0)
118
+ rubocop-ast (>= 1.45.0, < 2.0)
119
119
  ruby-progressbar (~> 1.7)
120
120
  unicode-display_width (>= 2.4.0, < 4.0)
121
- rubocop-ast (1.44.1)
121
+ rubocop-ast (1.45.0)
122
122
  parser (>= 3.3.7.2)
123
123
  prism (~> 1.4)
124
- rubocop-minitest (0.38.0)
124
+ rubocop-minitest (0.38.1)
125
125
  lint_roller (~> 1.1)
126
126
  rubocop (>= 1.75.0, < 2.0)
127
127
  rubocop-ast (>= 1.38.0, < 2.0)
@@ -168,22 +168,22 @@ PLATFORMS
168
168
  x86_64-linux
169
169
 
170
170
  DEPENDENCIES
171
- base64 (> 0)
171
+ base64 (~> 0.3)
172
172
  baza.rb!
173
- factbase (> 0)
173
+ factbase (~> 0.11)
174
174
  minitest (~> 5.25)
175
175
  minitest-reporters (~> 1.7)
176
- os (> 0)
177
- qbash (> 0)
176
+ os (~> 1.1)
177
+ qbash (~> 0.4)
178
178
  rake (~> 13.2)
179
- random-port (> 0)
179
+ random-port (~> 0.7)
180
180
  rubocop (~> 1.73)
181
- rubocop-minitest (> 0)
181
+ rubocop-minitest (~> 0.38)
182
182
  rubocop-performance (~> 1.23)
183
- rubocop-rake (> 0)
183
+ rubocop-rake (~> 0.7)
184
184
  simplecov (~> 0.22)
185
185
  simplecov-cobertura (~> 2.1)
186
- wait_for (~> 0)
186
+ wait_for (~> 0.1)
187
187
  webmock (~> 3.24)
188
188
  webrick (~> 1.9)
189
189
  yard (~> 0.9)
data/baza.rb.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.license = 'MIT'
15
15
  s.summary = 'Zerocracy API Ruby Client'
16
16
  s.description =
17
- 'It is a Ruby client for Zerocracy API, allowing you to check your jobs ' \
17
+ 'It is a Ruby client for Zerocracy API, allowing you to check your job ' \
18
18
  'statuses, upload and download binaries, lock/unlock them, manage durables, ' \
19
19
  'and do everything else that is possible to do via the HTTP API.'
20
20
  s.authors = ['Yegor Bugayenko']
@@ -23,16 +23,16 @@ Gem::Specification.new do |s|
23
23
  s.files = `git ls-files`.split($RS)
24
24
  s.rdoc_options = ['--charset=UTF-8']
25
25
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
26
- s.add_dependency 'backtrace', '>0'
27
- s.add_dependency 'elapsed', '>0'
28
- s.add_dependency 'faraday', '>0'
29
- s.add_dependency 'faraday-http-cache', '>0'
30
- s.add_dependency 'faraday-multipart', '>0'
31
- s.add_dependency 'faraday-retry', '>0'
32
- s.add_dependency 'iri', '>0'
33
- s.add_dependency 'loog', '>0'
34
- s.add_dependency 'retries', '~>0'
35
- s.add_dependency 'tago', '~>0'
36
- s.add_dependency 'typhoeus', '~>1.3'
26
+ s.add_dependency 'backtrace', '~>0.4'
27
+ s.add_dependency 'elapsed', '~>0.0'
28
+ s.add_dependency 'faraday', '~>2.13'
29
+ s.add_dependency 'faraday-http-cache', '~>2.5'
30
+ s.add_dependency 'faraday-multipart', '~>1.1'
31
+ s.add_dependency 'faraday-retry', '~>2.3'
32
+ s.add_dependency 'iri', '~>0.11'
33
+ s.add_dependency 'loog', '~>0.6'
34
+ s.add_dependency 'retries', '~>0.0'
35
+ s.add_dependency 'tago', '~>0.0'
36
+ s.add_dependency 'typhoeus', '~>1.4'
37
37
  s.metadata['rubygems_mfa_required'] = 'true'
38
38
  end
data/lib/baza-rb/fake.rb CHANGED
@@ -213,12 +213,14 @@ class BazaRb::Fake
213
213
  # @param [String] owner Identifier of who is taking the job
214
214
  # @param [String] zip The local file path where the job's ZIP will be saved
215
215
  # @return [Boolean] Always returns TRUE and creates an empty file
216
+ # rubocop:disable Naming/PredicateMethod
216
217
  def pop(owner, zip)
217
218
  assert_owner(owner)
218
219
  FileUtils.mkdir_p(File.dirname(zip))
219
220
  FileUtils.touch(zip)
220
221
  true
221
222
  end
223
+ # rubocop:enable Naming/PredicateMethod
222
224
 
223
225
  # Submit a ZIP archive to finish a previously popped job.
224
226
  #
@@ -13,5 +13,5 @@
13
13
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
14
14
  # License:: MIT
15
15
  class BazaRb
16
- VERSION = '0.5.0'
16
+ VERSION = '0.6.0'
17
17
  end
data/lib/baza-rb.rb CHANGED
@@ -69,7 +69,7 @@ class BazaRb
69
69
  nick = nil
70
70
  elapsed(@loog) do
71
71
  ret =
72
- with_retries(max_tries: @retries, rescue: TimedOut) do
72
+ retry_it do
73
73
  checked(
74
74
  Typhoeus::Request.get(
75
75
  home.append('whoami').to_s,
@@ -91,7 +91,7 @@ class BazaRb
91
91
  z = nil
92
92
  elapsed(@loog) do
93
93
  ret =
94
- with_retries(max_tries: @retries, rescue: TimedOut) do
94
+ retry_it do
95
95
  checked(
96
96
  Typhoeus::Request.get(
97
97
  home.append('account').append('balance').to_s,
@@ -120,7 +120,7 @@ class BazaRb
120
120
  id = 0
121
121
  hdrs = headers.merge(
122
122
  'Content-Type' => 'application/octet-stream',
123
- 'Content-Length' => data.size
123
+ 'Content-Length' => data.bytesize
124
124
  )
125
125
  unless meta.empty?
126
126
  hdrs = hdrs.merge('X-Zerocracy-Meta' => meta.map { |v| Base64.encode64(v).delete("\n") }.join(' '))
@@ -133,7 +133,7 @@ class BazaRb
133
133
  }
134
134
  elapsed(@loog) do
135
135
  ret =
136
- with_retries(max_tries: @retries, rescue: TimedOut) do
136
+ retry_it do
137
137
  checked(
138
138
  Typhoeus::Request.put(
139
139
  home.append('push').append(name).to_s,
@@ -142,7 +142,7 @@ class BazaRb
142
142
  )
143
143
  end
144
144
  id = ret.body.to_i
145
- throw :"Pushed #{data.size} bytes to #{@host}, job ID is ##{id}"
145
+ throw :"Pushed #{data.bytesize} bytes to #{@host}, job ID is ##{id}"
146
146
  end
147
147
  id
148
148
  end
@@ -172,13 +172,13 @@ class BazaRb
172
172
  request.on_body do |chunk|
173
173
  f.write(chunk)
174
174
  end
175
- with_retries(max_tries: @retries, rescue: TimedOut) do
175
+ retry_it do
176
176
  request.run
177
177
  end
178
178
  checked(request.response)
179
179
  end
180
180
  data = File.binread(file)
181
- throw :"Pulled #{data.size} bytes of job ##{id} factbase at #{@host}"
181
+ throw :"Pulled #{data.bytesize} bytes of job ##{id} factbase at #{@host}"
182
182
  end
183
183
  end
184
184
  data
@@ -192,10 +192,10 @@ class BazaRb
192
192
  def finished?(id)
193
193
  raise 'The ID of the job is nil' if id.nil?
194
194
  raise 'The ID of the job must be a positive integer' unless id.positive?
195
- finished = false
195
+ fin = false
196
196
  elapsed(@loog) do
197
197
  ret =
198
- with_retries(max_tries: @retries, rescue: TimedOut) do
198
+ retry_it do
199
199
  checked(
200
200
  Typhoeus::Request.get(
201
201
  home.append('finished').append(id).to_s,
@@ -203,10 +203,10 @@ class BazaRb
203
203
  )
204
204
  )
205
205
  end
206
- finished = ret.body == 'yes'
207
- throw :"The job ##{id} is #{finished ? '' : 'not yet '}finished at #{@host}"
206
+ fin = ret.body == 'yes'
207
+ throw :"The job ##{id} is #{'not yet ' unless fin}finished at #{@host}#{" (#{ret.body.inspect})" unless fin}"
208
208
  end
209
- finished
209
+ fin
210
210
  end
211
211
 
212
212
  # Read and return the stdout of the job.
@@ -219,7 +219,7 @@ class BazaRb
219
219
  stdout = ''
220
220
  elapsed(@loog) do
221
221
  ret =
222
- with_retries(max_tries: @retries, rescue: TimedOut) do
222
+ retry_it do
223
223
  checked(
224
224
  Typhoeus::Request.get(
225
225
  home.append('stdout').append("#{id}.txt").to_s,
@@ -243,7 +243,7 @@ class BazaRb
243
243
  code = 0
244
244
  elapsed(@loog) do
245
245
  ret =
246
- with_retries(max_tries: @retries, rescue: TimedOut) do
246
+ retry_it do
247
247
  checked(
248
248
  Typhoeus::Request.get(
249
249
  home.append('exit').append("#{id}.txt").to_s,
@@ -267,7 +267,7 @@ class BazaRb
267
267
  verdict = ''
268
268
  elapsed(@loog) do
269
269
  ret =
270
- with_retries(max_tries: @retries, rescue: TimedOut) do
270
+ retry_it do
271
271
  checked(
272
272
  Typhoeus::Request.get(
273
273
  home.append('jobs').append(id).append('verified.txt').to_s,
@@ -291,7 +291,7 @@ class BazaRb
291
291
  raise 'The "owner" of the lock is nil' if owner.nil?
292
292
  elapsed(@loog) do
293
293
  ret =
294
- with_retries(max_tries: @retries, rescue: TimedOut) do
294
+ retry_it do
295
295
  checked(
296
296
  Typhoeus::Request.get(
297
297
  home.append('lock').append(name).add(owner:).to_s,
@@ -315,7 +315,7 @@ class BazaRb
315
315
  raise 'The "owner" of the lock is nil' if owner.nil?
316
316
  raise 'The "owner" of the lock may not be empty' if owner.empty?
317
317
  elapsed(@loog) do
318
- with_retries(max_tries: @retries, rescue: TimedOut) do
318
+ retry_it do
319
319
  checked(
320
320
  Typhoeus::Request.get(
321
321
  home.append('unlock').append(name).add(owner:).to_s,
@@ -338,7 +338,7 @@ class BazaRb
338
338
  job = nil
339
339
  elapsed(@loog) do
340
340
  ret =
341
- with_retries(max_tries: @retries, rescue: TimedOut) do
341
+ retry_it do
342
342
  checked(
343
343
  Typhoeus::Request.get(
344
344
  home.append('recent').append("#{name}.txt").to_s,
@@ -362,7 +362,7 @@ class BazaRb
362
362
  exists = false
363
363
  elapsed(@loog) do
364
364
  ret =
365
- with_retries(max_tries: @retries, rescue: TimedOut) do
365
+ retry_it do
366
366
  checked(
367
367
  Typhoeus::Request.get(
368
368
  home.append('exists').append(name).to_s,
@@ -390,7 +390,7 @@ class BazaRb
390
390
  id = nil
391
391
  elapsed(@loog) do
392
392
  ret =
393
- with_retries(max_tries: @retries, rescue: TimedOut) do
393
+ retry_it do
394
394
  checked(
395
395
  Typhoeus::Request.post(
396
396
  home.append('durables').append('place').to_s,
@@ -423,7 +423,7 @@ class BazaRb
423
423
  raise 'The "file" of the durable is nil' if file.nil?
424
424
  raise "The file '#{file}' is absent" unless File.exist?(file)
425
425
  elapsed(@loog) do
426
- with_retries(max_tries: @retries, rescue: TimedOut) do
426
+ retry_it do
427
427
  checked(
428
428
  Typhoeus::Request.put(
429
429
  home.append('durables').append(id).to_s,
@@ -461,7 +461,7 @@ class BazaRb
461
461
  request.on_body do |chunk|
462
462
  f.write(chunk)
463
463
  end
464
- with_retries(max_tries: @retries, rescue: TimedOut) do
464
+ retry_it do
465
465
  request.run
466
466
  end
467
467
  checked(request.response)
@@ -480,7 +480,7 @@ class BazaRb
480
480
  raise 'The "owner" of the lock is nil' if owner.nil?
481
481
  raise 'The "owner" of the lock may not be empty' if owner.empty?
482
482
  elapsed(@loog) do
483
- with_retries(max_tries: @retries, rescue: TimedOut) do
483
+ retry_it do
484
484
  checked(
485
485
  Typhoeus::Request.get(
486
486
  home.append('durables').append(id).append('lock').add(owner:).to_s,
@@ -503,7 +503,7 @@ class BazaRb
503
503
  raise 'The "owner" of the lock is nil' if owner.nil?
504
504
  raise 'The "owner" of the lock may not be empty' if owner.empty?
505
505
  elapsed(@loog) do
506
- with_retries(max_tries: @retries, rescue: TimedOut) do
506
+ retry_it do
507
507
  checked(
508
508
  Typhoeus::Request.get(
509
509
  home.append('durables').append(id).append('unlock').add(owner:).to_s,
@@ -516,6 +516,38 @@ class BazaRb
516
516
  end
517
517
  end
518
518
 
519
+ # Find a durable by job name and file name.
520
+ #
521
+ # @param [String] jname The name of the job
522
+ # @param [String] file The file name
523
+ # @return [Integer, nil] The ID of the durable if found, nil if not found
524
+ def durable_find(jname, file)
525
+ raise 'The "jname" is nil' if jname.nil?
526
+ raise 'The "jname" may not be empty' if jname.empty?
527
+ raise 'The "file" is nil' if file.nil?
528
+ raise 'The "file" may not be empty' if file.empty?
529
+ id = nil
530
+ elapsed(@loog) do
531
+ ret =
532
+ retry_it do
533
+ checked(
534
+ Typhoeus::Request.get(
535
+ home.append('durables').append('find').add(jname:, file:).to_s,
536
+ headers:
537
+ ),
538
+ [200, 404]
539
+ )
540
+ end
541
+ if ret.code == 200
542
+ id = ret.body.to_i
543
+ throw :"Found durable ##{id} for job \"#{jname}\" file \"#{file}\" at #{@host}"
544
+ else
545
+ throw :"Durable not found for job \"#{jname}\" file \"#{file}\" at #{@host}"
546
+ end
547
+ end
548
+ id
549
+ end
550
+
519
551
  # Transfer funds to another user.
520
552
  #
521
553
  # @param [String] recipient GitHub username of the recipient (e.g. "yegor256")
@@ -539,7 +571,7 @@ class BazaRb
539
571
  body['job'] = job unless job.nil?
540
572
  elapsed(@loog) do
541
573
  ret =
542
- with_retries(max_tries: @retries, rescue: TimedOut) do
574
+ retry_it do
543
575
  checked(
544
576
  Typhoeus::Request.post(
545
577
  home.append('account').append('transfer').to_s,
@@ -582,7 +614,7 @@ class BazaRb
582
614
  }
583
615
  elapsed(@loog) do
584
616
  ret =
585
- with_retries(max_tries: @retries, rescue: TimedOut) do
617
+ retry_it do
586
618
  checked(
587
619
  Typhoeus::Request.post(
588
620
  home.append('account').append('fee').to_s,
@@ -629,7 +661,7 @@ class BazaRb
629
661
  request.on_body do |chunk|
630
662
  f.write(chunk)
631
663
  end
632
- with_retries(max_tries: @retries, rescue: TimedOut) do
664
+ retry_it do
633
665
  request.run
634
666
  end
635
667
  ret = request.response
@@ -672,7 +704,7 @@ class BazaRb
672
704
  raise 'The "zip" of the job is nil' if zip.nil?
673
705
  raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
674
706
  elapsed(@loog) do
675
- with_retries(max_tries: @retries, rescue: TimedOut) do
707
+ retry_it do
676
708
  checked(
677
709
  Typhoeus::Request.put(
678
710
  home.append('finish').add(id:).to_s,
@@ -705,7 +737,7 @@ class BazaRb
705
737
  # @raise [ServerFailure] If the valve operation fails
706
738
  def enter(name, badge, why, job)
707
739
  elapsed(@loog, intro: "Entered valve #{badge} to #{name}") do
708
- with_retries(max_tries: @retries, rescue: TimedOut) do
740
+ retry_it do
709
741
  ret = checked(
710
742
  Typhoeus::Request.get(
711
743
  home.append('valves').append('result').add(badge:).to_s,
@@ -746,7 +778,7 @@ class BazaRb
746
778
  def csrf
747
779
  token = nil
748
780
  elapsed(@loog) do
749
- with_retries(max_tries: @retries, rescue: TimedOut) do
781
+ retry_it do
750
782
  token = checked(
751
783
  Typhoeus::Request.get(
752
784
  home.append('csrf').to_s,
@@ -778,7 +810,7 @@ class BazaRb
778
810
  {
779
811
  'Content-Type' => 'application/zip',
780
812
  'Content-Encoding' => 'gzip',
781
- 'Content-Length' => body.size
813
+ 'Content-Length' => body.bytesize
782
814
  }
783
815
  )
784
816
  params.merge(body:, headers:)
@@ -800,6 +832,10 @@ class BazaRb
800
832
  .scheme(@ssl ? 'https' : 'http')
801
833
  end
802
834
 
835
+ def retry_it(&)
836
+ with_retries(max_tries: @retries, rescue: TimedOut, &)
837
+ end
838
+
803
839
  # Check the HTTP response and return it.
804
840
  #
805
841
  # @param [Typhoeus::Response] ret The response
@@ -840,7 +876,9 @@ class BazaRb
840
876
  ", most probably you are trying to reach a wrong server, which doesn't " \
841
877
  'have the URL that it is expected to have'
842
878
  when 0
843
- msg += ', most likely an internal error'
879
+ msg +=
880
+ ', most likely a connection failure, timeout, or SSL error ' \
881
+ "(r:#{ret.return_code}, m:#{ret.return_message})"
844
882
  end
845
883
  @loog.error(msg)
846
884
  raise ServerFailure, msg
data/test/test_baza-rb.rb CHANGED
@@ -22,7 +22,7 @@ require_relative '../lib/baza-rb'
22
22
  # License:: MIT
23
23
  class TestBazaRb < Minitest::Test
24
24
  # The token to use for testing, in Zerocracy.com:
25
- TOKEN = '00000000-0000-0000-0000-000000000000'
25
+ TOKEN = 'ZRCY-00000000-0000-0000-0000-000000000000'
26
26
 
27
27
  # The host of the production platform:
28
28
  HOST = 'api.zerocracy.com'
@@ -31,9 +31,9 @@ class TestBazaRb < Minitest::Test
31
31
  PORT = 443
32
32
 
33
33
  # Live agent:
34
- LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::NULL)
34
+ LIVE = BazaRb.new(HOST, PORT, TOKEN, loog: Loog::VERBOSE)
35
35
 
36
- def test_live_push
36
+ def test_live_full_cycle
37
37
  WebMock.enable_net_connect!
38
38
  skip('We are offline') unless we_are_online
39
39
  fb = Factbase.new
@@ -44,7 +44,12 @@ class TestBazaRb < Minitest::Test
44
44
  assert(LIVE.name_exists?(n))
45
45
  assert_predicate(LIVE.recent(n), :positive?)
46
46
  id = LIVE.recent(n)
47
- assert(wait_for(200) { LIVE.finished?(id) })
47
+ assert(
48
+ wait_for(8 * 60) do
49
+ sleep(5)
50
+ LIVE.finished?(id)
51
+ end
52
+ )
48
53
  refute_nil(LIVE.pull(id))
49
54
  refute_nil(LIVE.stdout(id))
50
55
  refute_nil(LIVE.exit_code(id))
@@ -90,7 +95,10 @@ class TestBazaRb < Minitest::Test
90
95
  Dir.mktmpdir do |dir|
91
96
  file = File.join(dir, "#{fake_name}.bin")
92
97
  File.binwrite(file, 'hello')
93
- id = LIVE.durable_place(fake_name, file)
98
+ jname = fake_name
99
+ refute(LIVE.durable_find(jname, File.basename(file)))
100
+ id = LIVE.durable_place(jname, file)
101
+ assert_equal(id, LIVE.durable_find(jname, File.basename(file)))
94
102
  owner = fake_name
95
103
  LIVE.durable_lock(id, owner)
96
104
  LIVE.durable_load(id, file)
@@ -371,30 +379,32 @@ class TestBazaRb < Minitest::Test
371
379
  def test_push_compressed_content
372
380
  WebMock.enable_net_connect!
373
381
  skip('We are offline') unless we_are_online
382
+ fb = Factbase.new
383
+ fb.insert.foo = 'test-' * 10_000
374
384
  req =
375
385
  with_http_server(200, 'yes') do |baza|
376
- baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
386
+ baza.push('simple', fb.export, %w[meta1 meta2 meta3])
377
387
  end
378
388
  assert_equal('application/zip', req.content_type)
379
389
  assert_equal('gzip', req['content-encoding'])
380
390
  body = Zlib::GzipReader.zcat(StringIO.new(req.body))
381
- assert_equal('hello, world!', body)
391
+ assert_equal(fb.export, body)
382
392
  end
383
393
 
384
394
  def test_push_compression_disabled
385
395
  WebMock.enable_net_connect!
386
- skip('We are offline') unless we_are_online
396
+ fb = Factbase.new
397
+ fb.insert.foo = 'test-' * 10_000
387
398
  req =
388
399
  with_http_server(200, 'yes', compress: false) do |baza|
389
- baza.push('simple', 'hello, world!', %w[meta1 meta2 meta3])
400
+ baza.push('simple', fb.export, %w[meta1 meta2 meta3])
390
401
  end
391
402
  assert_equal('application/octet-stream', req.content_type)
392
- assert_equal('hello, world!', req.body)
403
+ assert_equal(fb.export, req.body)
393
404
  end
394
405
 
395
406
  def test_with_very_short_timeout
396
407
  WebMock.enable_net_connect!
397
- skip('We are offline') unless we_are_online
398
408
  host = '127.0.0.1'
399
409
  RandomPort::Pool::SINGLETON.acquire do |port|
400
410
  server = TCPServer.new(host, port)
@@ -413,11 +423,13 @@ class TestBazaRb < Minitest::Test
413
423
  BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
414
424
  end.message, 'timed out in'
415
425
  )
416
- t.join
426
+ t.terminate
427
+ assert(t.join(1))
417
428
  end
418
429
  end
419
430
 
420
431
  def test_durable_save
432
+ WebMock.disable_net_connect!
421
433
  Dir.mktmpdir do |dir|
422
434
  file = File.join(dir, 'test.txt')
423
435
  File.write(file, 'test content')
@@ -429,6 +441,7 @@ class TestBazaRb < Minitest::Test
429
441
  end
430
442
 
431
443
  def test_durable_load
444
+ WebMock.disable_net_connect!
432
445
  Dir.mktmpdir do |dir|
433
446
  file = File.join(dir, 'loaded.txt')
434
447
  stub_request(:get, 'https://example.org:443/durables/42')
@@ -440,6 +453,7 @@ class TestBazaRb < Minitest::Test
440
453
  end
441
454
 
442
455
  def test_durable_lock
456
+ WebMock.disable_net_connect!
443
457
  stub_request(:get, 'https://example.org:443/durables/42/lock?owner=test-owner')
444
458
  .with(headers: { 'X-Zerocracy-Token' => '000' })
445
459
  .to_return(status: 302)
@@ -447,6 +461,7 @@ class TestBazaRb < Minitest::Test
447
461
  end
448
462
 
449
463
  def test_durable_unlock
464
+ WebMock.disable_net_connect!
450
465
  stub_request(:get, 'https://example.org:443/durables/42/unlock?owner=test-owner')
451
466
  .with(headers: { 'X-Zerocracy-Token' => '000' })
452
467
  .to_return(status: 302)
@@ -454,6 +469,7 @@ class TestBazaRb < Minitest::Test
454
469
  end
455
470
 
456
471
  def test_fee
472
+ WebMock.disable_net_connect!
457
473
  stub_request(:get, 'https://example.org:443/csrf')
458
474
  .with(headers: { 'X-Zerocracy-Token' => '000' })
459
475
  .to_return(status: 200, body: 'csrf-token')
@@ -474,6 +490,7 @@ class TestBazaRb < Minitest::Test
474
490
  end
475
491
 
476
492
  def test_enter
493
+ WebMock.disable_net_connect!
477
494
  stub_request(:get, 'https://example.org:443/valves/result?badge=test-badge')
478
495
  .with(headers: { 'X-Zerocracy-Token' => '000' })
479
496
  .to_return(status: 200, body: 'cached result')
@@ -482,6 +499,7 @@ class TestBazaRb < Minitest::Test
482
499
  end
483
500
 
484
501
  def test_enter_not_cached
502
+ WebMock.disable_net_connect!
485
503
  stub_request(:get, 'https://example.org:443/valves/result?badge=test-badge')
486
504
  .with(headers: { 'X-Zerocracy-Token' => '000' })
487
505
  .to_return(status: 204)
@@ -504,27 +522,51 @@ class TestBazaRb < Minitest::Test
504
522
  assert_equal('new result', result)
505
523
  end
506
524
 
525
+ def test_durable_find_found
526
+ WebMock.disable_net_connect!
527
+ stub_request(:get, 'https://example.org:443/durables/find?jname=test-job&file=test.txt')
528
+ .with(headers: { 'X-Zerocracy-Token' => '000' })
529
+ .to_return(status: 200, body: '42')
530
+ id = fake_baza.durable_find('test-job', 'test.txt')
531
+ assert_equal(42, id)
532
+ end
533
+
534
+ def test_durable_find_not_found
535
+ WebMock.disable_net_connect!
536
+ stub_request(:get, 'https://example.org:443/durables/find?jname=test-job&file=test.txt')
537
+ .with(headers: { 'X-Zerocracy-Token' => '000' })
538
+ .to_return(status: 404)
539
+ id = fake_baza.durable_find('test-job', 'test.txt')
540
+ assert_nil(id)
541
+ end
542
+
507
543
  def test_checked_with_500_error
544
+ WebMock.disable_net_connect!
508
545
  stub_request(:get, 'https://example.org:443/test')
509
546
  .with(headers: { 'X-Zerocracy-Token' => '000' })
510
547
  .to_return(status: 500)
511
548
  error =
512
549
  assert_raises(BazaRb::ServerFailure) do
513
- fake_baza.send(:checked,
514
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
550
+ fake_baza.send(
551
+ :checked,
552
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
553
+ )
515
554
  end
516
555
  assert_includes(error.message, 'Invalid response code #500')
517
556
  assert_includes(error.message, "most probably it's an internal error on the server")
518
557
  end
519
558
 
520
559
  def test_checked_with_503_error
560
+ WebMock.disable_net_connect!
521
561
  stub_request(:get, 'https://example.org:443/test')
522
562
  .with(headers: { 'X-Zerocracy-Token' => '000' })
523
563
  .to_return(status: 503, headers: { 'X-Zerocracy-Failure' => 'Service unavailable' })
524
564
  error =
525
565
  assert_raises(BazaRb::ServerFailure) do
526
- fake_baza.send(:checked,
527
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
566
+ fake_baza.send(
567
+ :checked,
568
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
569
+ )
528
570
  end
529
571
  assert_includes(error.message, 'Invalid response code #503')
530
572
  assert_includes(error.message, "most probably it's an internal error on the server")
@@ -532,32 +574,39 @@ class TestBazaRb < Minitest::Test
532
574
  end
533
575
 
534
576
  def test_checked_with_404_error
577
+ WebMock.disable_net_connect!
535
578
  stub_request(:get, 'https://example.org:443/test')
536
579
  .with(headers: { 'X-Zerocracy-Token' => '000' })
537
580
  .to_return(status: 404)
538
581
  error =
539
582
  assert_raises(BazaRb::ServerFailure) do
540
- fake_baza.send(:checked,
541
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
583
+ fake_baza.send(
584
+ :checked,
585
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
586
+ )
542
587
  end
543
588
  assert_includes(error.message, 'Invalid response code #404')
544
589
  assert_includes(error.message, 'most probably you are trying to reach a wrong server')
545
590
  end
546
591
 
547
592
  def test_checked_with_0_error
593
+ WebMock.disable_net_connect!
548
594
  stub_request(:get, 'https://example.org:443/test')
549
595
  .with(headers: { 'X-Zerocracy-Token' => '000' })
550
596
  .to_return(status: 0)
551
597
  error =
552
598
  assert_raises(BazaRb::ServerFailure) do
553
- fake_baza.send(:checked,
554
- Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' }))
599
+ fake_baza.send(
600
+ :checked,
601
+ Typhoeus.get('https://example.org:443/test', headers: { 'X-Zerocracy-Token' => '000' })
602
+ )
555
603
  end
556
604
  assert_includes(error.message, 'Invalid response code #0')
557
- assert_includes(error.message, 'most likely an internal error')
605
+ assert_includes(error.message, 'most likely a connection failure')
558
606
  end
559
607
 
560
608
  def test_push_without_compression
609
+ WebMock.disable_net_connect!
561
610
  baza = BazaRb.new('example.org', 443, '000', loog: Loog::NULL, compress: false)
562
611
  stub_request(:put, 'https://example.org:443/push/test')
563
612
  .with(
@@ -578,7 +627,6 @@ class TestBazaRb < Minitest::Test
578
627
  def with_http_server(code, response, opts = {})
579
628
  opts = { ssl: false, timeout: 1 }.merge(opts)
580
629
  WebMock.enable_net_connect!
581
- skip('We are offline') unless we_are_online
582
630
  req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
583
631
  host = '127.0.0.1'
584
632
  RandomPort::Pool::SINGLETON.acquire do |port|
@@ -587,12 +635,18 @@ class TestBazaRb < Minitest::Test
587
635
  Thread.new do
588
636
  socket = server.accept
589
637
  req.parse(socket)
590
- req.body
591
- socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
638
+ body = req.body
639
+ len = req.header['content-length'].first.to_i
640
+ if body.nil? || len == body.size
641
+ socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
642
+ else
643
+ socket.puts "HTTP/1.1 400 Bad Request\r\n"
644
+ end
592
645
  socket.close
593
646
  end
594
647
  yield BazaRb.new(host, port, '0000', **opts)
595
- t.join
648
+ t.terminate
649
+ assert(t.join(1))
596
650
  end
597
651
  req
598
652
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -13,157 +13,157 @@ dependencies:
13
13
  name: backtrace
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">"
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0'
18
+ version: '0.4'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - ">"
23
+ - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0'
25
+ version: '0.4'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: elapsed
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - ">"
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '0.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">"
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '0.0'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: faraday
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">"
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '2.13'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">"
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '2.13'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: faraday-http-cache
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">"
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '2.5'
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">"
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '2.5'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: faraday-multipart
70
70
  requirement: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">"
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '1.1'
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">"
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: '1.1'
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: faraday-retry
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">"
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: '2.3'
89
89
  type: :runtime
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">"
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0'
95
+ version: '2.3'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: iri
98
98
  requirement: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ">"
100
+ - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0'
102
+ version: '0.11'
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - ">"
107
+ - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: '0.11'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: loog
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ">"
114
+ - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '0'
116
+ version: '0.6'
117
117
  type: :runtime
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - ">"
121
+ - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '0'
123
+ version: '0.6'
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: retries
126
126
  requirement: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '0'
130
+ version: '0.0'
131
131
  type: :runtime
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: '0.0'
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: tago
140
140
  requirement: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0'
144
+ version: '0.0'
145
145
  type: :runtime
146
146
  prerelease: false
147
147
  version_requirements: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '0'
151
+ version: '0.0'
152
152
  - !ruby/object:Gem::Dependency
153
153
  name: typhoeus
154
154
  requirement: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '1.3'
158
+ version: '1.4'
159
159
  type: :runtime
160
160
  prerelease: false
161
161
  version_requirements: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '1.3'
166
- description: It is a Ruby client for Zerocracy API, allowing you to check your jobs
165
+ version: '1.4'
166
+ description: It is a Ruby client for Zerocracy API, allowing you to check your job
167
167
  statuses, upload and download binaries, lock/unlock them, manage durables, and do
168
168
  everything else that is possible to do via the HTTP API.
169
169
  email: yegor256@gmail.com