baza.rb 0.0.4 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ac6dd23ce75d129ed2569730f17c38477220e4637736acf630b3a5b1233e30a
4
- data.tar.gz: 86036e407483b556df491bc25b9b37ba7a39fd054ec8d5005f7d5f5ef5af1139
3
+ metadata.gz: 9ffabe02ed963b25b7b763832d2b67fba6fd26739ab1656af0613007390b4804
4
+ data.tar.gz: 58a9abffa52a09106537205d8a806e87084a3ceb0454ba509373bc3c9bab9a3b
5
5
  SHA512:
6
- metadata.gz: abc122fe9f3500aee61644f9605fdd11b5d4afbf593ccbcf000be18802799a144573822aa51aa88fe3b84140a0dd2be9d04001a5cdbb5c9e00d7cf28e6f39e00
7
- data.tar.gz: 85d8540811e627ee942821862da29b2578d92362dd889d9f12c85f8713377cd30151213449ee079d63702d2bf47d927de1892b49755ee28407cf13f569ca82ab
6
+ metadata.gz: d274ead41371254054b7ddef2e4929e197550a4a4fbdc168c7cd4960317a7aa10bbda453430b5ab1c92f58523c9f3c6325517069217a2a5e1137330890a117de
7
+ data.tar.gz: 1e7429b00c744708dddf0f930c37ee93f3a4675d8dfd9ef5e16db5630afb853a6eb9618d5132158812e5e5b104871fc761003b9bdaca07f799078fc4b33cb1d3
data/Gemfile.lock CHANGED
@@ -65,7 +65,7 @@ GEM
65
65
  erubi (1.13.0)
66
66
  ethon (0.16.0)
67
67
  ffi (>= 1.15.0)
68
- factbase (0.3.0)
68
+ factbase (0.4.0)
69
69
  backtrace (> 0)
70
70
  decoor (> 0)
71
71
  json (~> 2.7)
@@ -123,7 +123,7 @@ GEM
123
123
  nokogiri (1.16.7-x86_64-linux)
124
124
  racc (~> 1.4)
125
125
  others (0.0.3)
126
- parallel (1.26.1)
126
+ parallel (1.26.2)
127
127
  parser (3.3.4.2)
128
128
  ast (~> 2.4.1)
129
129
  racc
@@ -163,7 +163,7 @@ GEM
163
163
  reline (0.5.9)
164
164
  io-console (~> 0.5)
165
165
  retries (0.0.5)
166
- rexml (3.3.4)
166
+ rexml (3.3.5)
167
167
  strscan
168
168
  rspec-core (3.13.0)
169
169
  rspec-support (~> 3.13.0)
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  class BazaRb
29
- VERSION = '0.0.4'
29
+ VERSION = '0.0.5'
30
30
  end
data/lib/baza-rb.rb CHANGED
@@ -180,6 +180,27 @@ class BazaRb
180
180
  code
181
181
  end
182
182
 
183
+ # Read and return the verification verdict of the job.
184
+ # @param [Integer] id The ID of the job on the server
185
+ # @return [String] The verdict
186
+ def verified(id)
187
+ verdict = 0
188
+ elapsed(@loog) do
189
+ ret =
190
+ with_retries(max_tries: @retries) do
191
+ checked(
192
+ Typhoeus::Request.get(
193
+ home.append('jobs').append(id).append('verified.txt').to_s,
194
+ headers:
195
+ )
196
+ )
197
+ end
198
+ verdict = ret.body
199
+ throw :"The verdict of the job ##{id} is #{verdict.inspect}"
200
+ end
201
+ verdict
202
+ end
203
+
183
204
  # Lock the name.
184
205
  # @param [String] name The name of the job on the server
185
206
  # @param [String] owner The owner of the lock (any string)
@@ -283,7 +304,7 @@ class BazaRb
283
304
  )
284
305
  end
285
306
  id = ret.headers['X-Zerocracy-DurableId'].to_i
286
- throw :"Durable ##{id} placed for job \"#{jname}\" at #{@host}"
307
+ throw :"Durable ##{id} (#{file}) placed for job \"#{jname}\" at #{@host}"
287
308
  end
288
309
  id
289
310
  end
@@ -428,13 +449,15 @@ class BazaRb
428
449
  allowed = [allowed] unless allowed.is_a?(Array)
429
450
  mtd = (ret.request.original_options[:method] || '???').upcase
430
451
  url = ret.effective_url
431
- log = "#{mtd} #{url} -> #{ret.code}"
452
+ raise "#{mtd} #{url} timed out in #{ret.total_time}s" if ret.return_code == :operation_timedout
453
+ log = "#{mtd} #{url} -> #{ret.code} (#{format('%0.2f', ret.total_time)}s)"
432
454
  if allowed.include?(ret.code)
433
455
  @loog.debug(log)
434
456
  return ret
435
457
  end
436
458
  @loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}")
437
459
  headers = ret.headers || {}
460
+ p ret
438
461
  msg = [
439
462
  "Invalid response code ##{ret.code} ",
440
463
  "at #{mtd} #{url}",
data/test/test_baza-rb.rb CHANGED
@@ -58,6 +58,7 @@ class TestBazaRb < Minitest::Test
58
58
  assert(!LIVE.pull(id).nil?)
59
59
  assert(!LIVE.stdout(id).nil?)
60
60
  assert(!LIVE.exit_code(id).nil?)
61
+ assert(!LIVE.verified(id).nil?)
61
62
  owner = 'baza.rb testing'
62
63
  assert(!LIVE.lock(n, owner).nil?)
63
64
  assert(!LIVE.unlock(n, owner).nil?)
@@ -215,6 +216,30 @@ class TestBazaRb < Minitest::Test
215
216
  assert_equal('hello, world!', req.body)
216
217
  end
217
218
 
219
+ def test_with_very_short_timeout
220
+ WebMock.enable_net_connect!
221
+ host = '127.0.0.1'
222
+ RandomPort::Pool::SINGLETON.acquire do |port|
223
+ server = TCPServer.new(host, port)
224
+ t =
225
+ Thread.new do
226
+ socket = server.accept
227
+ req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
228
+ req.parse(socket)
229
+ req.body
230
+ sleep 0.1
231
+ socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nabc"
232
+ socket.close
233
+ end
234
+ assert(
235
+ assert_raises do
236
+ BazaRb.new(host, port, '0000', ssl: false, timeout: 0.01).push('x', 'y', [])
237
+ end.message.include?('timed out in')
238
+ )
239
+ t.join
240
+ end
241
+ end
242
+
218
243
  private
219
244
 
220
245
  def with_http_server(code, response, opts = {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-11 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace