baza.rb 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79bdf99ef89239ac525987bbde20700d7c2ce13d05198df581729b0bd73bec6b
4
- data.tar.gz: 8acc9a7baef255599d65b3ef6092f35c7355b22ce6ea09cca490a0da0e2dd429
3
+ metadata.gz: 9ffabe02ed963b25b7b763832d2b67fba6fd26739ab1656af0613007390b4804
4
+ data.tar.gz: 58a9abffa52a09106537205d8a806e87084a3ceb0454ba509373bc3c9bab9a3b
5
5
  SHA512:
6
- metadata.gz: 8d03964151b2b9eb9f7362425a877321d31d4bbce17c0e500f7f151d95cb3bde298fef2edc0f870c68e5c4447c6c2b82793ebc0a2e44508bf5182fad35080103
7
- data.tar.gz: e45fdea8eb1df4ac95cf8a43cca2e6899bd997dd6140fe5eb9c80315cdc11301b6dc5eeb57a3b9683a6c7f67538bc31048e3c3069acca389ec3ab70dbeb66351
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)
data/baza.rb.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
28
  s.required_ruby_version = '>=3.0'
29
29
  s.name = 'baza.rb'
30
- s.version = Baza::VERSION
30
+ s.version = BazaRb::VERSION
31
31
  s.license = 'MIT'
32
32
  s.summary = 'Zerocracy API Ruby Client'
33
33
  s.description =
@@ -25,6 +25,6 @@
25
25
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
26
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
27
27
  # License:: MIT
28
- class Baza
29
- VERSION = '0.0.3'
28
+ class BazaRb
29
+ VERSION = '0.0.5'
30
30
  end
data/lib/baza-rb.rb CHANGED
@@ -20,12 +20,12 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require 'typhoeus'
24
- require 'retries'
23
+ require 'base64'
25
24
  require 'iri'
26
25
  require 'loog'
27
- require 'base64'
26
+ require 'retries'
28
27
  require 'tago'
28
+ require 'typhoeus'
29
29
  require_relative 'baza-rb/version'
30
30
 
31
31
  # Interface to the API of zerocracy.com.
@@ -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)
@@ -273,7 +294,7 @@ class BazaRb
273
294
  body: {
274
295
  'jname' => jname,
275
296
  'file' => File.basename(file),
276
- 'zip' => File.open(file, 'r')
297
+ 'zip' => File.open(file, 'rb')
277
298
  },
278
299
  headers:,
279
300
  connecttimeout: @timeout,
@@ -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
@@ -377,7 +398,7 @@ class BazaRb
377
398
 
378
399
  def headers
379
400
  {
380
- 'User-Agent' => "baza.rb #{Baza::VERSION}",
401
+ 'User-Agent' => "baza.rb #{BazaRb::VERSION}",
381
402
  'Connection' => 'close',
382
403
  'X-Zerocracy-Token' => @token
383
404
  }
@@ -428,16 +449,19 @@ 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 ")}")
459
+ headers = ret.headers || {}
460
+ p ret
437
461
  msg = [
438
462
  "Invalid response code ##{ret.code} ",
439
463
  "at #{mtd} #{url}",
440
- ret.headers['X-Zerocracy-Flash'] ? " (#{ret.headers['X-Zerocracy-Flash'].inspect})" : ''
464
+ headers['X-Zerocracy-Flash'] ? " (#{headers['X-Zerocracy-Flash'].inspect})" : ''
441
465
  ].join
442
466
  case ret.code
443
467
  when 500
@@ -446,7 +470,7 @@ class BazaRb
446
470
  'please report this to https://github.com/zerocracy/baza'
447
471
  when 503
448
472
  msg +=
449
- ", most probably it's an internal error on the server (#{ret.headers['X-Zerocracy-Failure'].inspect}), " \
473
+ ", most probably it's an internal error on the server (#{headers['X-Zerocracy-Failure'].inspect}), " \
450
474
  'please report this to https://github.com/zerocracy/baza.rb'
451
475
  when 404
452
476
  msg +=
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?)
@@ -167,7 +168,7 @@ class TestBazaRb < Minitest::Test
167
168
  with_http_server(200, 'yes') do |baza|
168
169
  baza.name_exists?('simple')
169
170
  end
170
- assert_equal("baza.rb #{Baza::VERSION}", req['user-agent'])
171
+ assert_equal("baza.rb #{BazaRb::VERSION}", req['user-agent'])
171
172
  end
172
173
 
173
174
  def test_push_with_meta
@@ -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.3
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