baza.rb 0.0.4 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ac6dd23ce75d129ed2569730f17c38477220e4637736acf630b3a5b1233e30a
4
- data.tar.gz: 86036e407483b556df491bc25b9b37ba7a39fd054ec8d5005f7d5f5ef5af1139
3
+ metadata.gz: 1e5d99494e1d40acfbb4e3528aa78da5c6f3db987d2a5adeef6e3b549dd7d39a
4
+ data.tar.gz: 935c8d8a3c2b91c75a9a65ff842661e21f2e6deeaa91349645a28970ad589011
5
5
  SHA512:
6
- metadata.gz: abc122fe9f3500aee61644f9605fdd11b5d4afbf593ccbcf000be18802799a144573822aa51aa88fe3b84140a0dd2be9d04001a5cdbb5c9e00d7cf28e6f39e00
7
- data.tar.gz: 85d8540811e627ee942821862da29b2578d92362dd889d9f12c85f8713377cd30151213449ee079d63702d2bf47d927de1892b49755ee28407cf13f569ca82ab
6
+ metadata.gz: a173d77d88af5c4c5c8d82ad6ec4a19d169a9759d1fe6c5a7932d2e3a222ca496c37b83a8158175f5f7a562b94c12c3572f22e9d66e65eb822b6ab75899ab9c5
7
+ data.tar.gz: 2ca69ab0a36e5fa0a52592a7873fe115ea079df503797b2d2cba64e4bd402952a5ac3a9ea7a4ffca5edc70d40cbcfd80c518d6261a70a2ce36506d49e28d1b60
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.6'
30
30
  end
data/lib/baza-rb.rb CHANGED
@@ -55,6 +55,10 @@ class BazaRb
55
55
  # @param [Array<String>] meta List of metas, possibly empty
56
56
  # @return [Integer] Job ID on the server
57
57
  def push(name, data, meta)
58
+ raise 'The "name" of the job is nil' if name.nil?
59
+ raise 'The "name" of the job may not be empty' if name.empty?
60
+ raise 'The "data" of the job is nil' if data.nil?
61
+ raise 'The "meta" of the job is nil' if meta.nil?
58
62
  id = 0
59
63
  hdrs = headers.merge(
60
64
  'Content-Type' => 'application/octet-stream',
@@ -89,6 +93,8 @@ class BazaRb
89
93
  # @param [Integer] id The ID of the job on the server
90
94
  # @return [Bytes] Binary data pulled
91
95
  def pull(id)
96
+ raise 'The ID of the job is nil' if id.nil?
97
+ raise 'The ID of the job must be a positive integer' unless id.positive?
92
98
  data = 0
93
99
  elapsed(@loog) do
94
100
  Tempfile.open do |file|
@@ -121,6 +127,8 @@ class BazaRb
121
127
  # @param [Integer] id The ID of the job on the server
122
128
  # @return [Boolean] TRUE if the job is already finished
123
129
  def finished?(id)
130
+ raise 'The ID of the job is nil' if id.nil?
131
+ raise 'The ID of the job must be a positive integer' unless id.positive?
124
132
  finished = false
125
133
  elapsed(@loog) do
126
134
  ret =
@@ -142,6 +150,8 @@ class BazaRb
142
150
  # @param [Integer] id The ID of the job on the server
143
151
  # @return [String] The stdout, as a text
144
152
  def stdout(id)
153
+ raise 'The ID of the job is nil' if id.nil?
154
+ raise 'The ID of the job must be a positive integer' unless id.positive?
145
155
  stdout = ''
146
156
  elapsed(@loog) do
147
157
  ret =
@@ -163,6 +173,8 @@ class BazaRb
163
173
  # @param [Integer] id The ID of the job on the server
164
174
  # @return [Integer] The exit code
165
175
  def exit_code(id)
176
+ raise 'The ID of the job is nil' if id.nil?
177
+ raise 'The ID of the job must be a positive integer' unless id.positive?
166
178
  code = 0
167
179
  elapsed(@loog) do
168
180
  ret =
@@ -180,10 +192,36 @@ class BazaRb
180
192
  code
181
193
  end
182
194
 
195
+ # Read and return the verification verdict of the job.
196
+ # @param [Integer] id The ID of the job on the server
197
+ # @return [String] The verdict
198
+ def verified(id)
199
+ raise 'The ID of the job is nil' if id.nil?
200
+ raise 'The ID of the job must be a positive integer' unless id.positive?
201
+ verdict = 0
202
+ elapsed(@loog) do
203
+ ret =
204
+ with_retries(max_tries: @retries) do
205
+ checked(
206
+ Typhoeus::Request.get(
207
+ home.append('jobs').append(id).append('verified.txt').to_s,
208
+ headers:
209
+ )
210
+ )
211
+ end
212
+ verdict = ret.body
213
+ throw :"The verdict of the job ##{id} is #{verdict.inspect}"
214
+ end
215
+ verdict
216
+ end
217
+
183
218
  # Lock the name.
184
219
  # @param [String] name The name of the job on the server
185
220
  # @param [String] owner The owner of the lock (any string)
186
221
  def lock(name, owner)
222
+ raise 'The "name" of the job is nil' if name.nil?
223
+ raise 'The "name" of the job may not be empty' if name.empty?
224
+ raise 'The "owner" of the lock is nil' if owner.nil?
187
225
  elapsed(@loog) do
188
226
  with_retries(max_tries: @retries) do
189
227
  checked(
@@ -202,6 +240,9 @@ class BazaRb
202
240
  # @param [String] name The name of the job on the server
203
241
  # @param [String] owner The owner of the lock (any string)
204
242
  def unlock(name, owner)
243
+ raise 'The "name" of the job is nil' if name.nil?
244
+ raise 'The "name" of the job may not be empty' if name.empty?
245
+ raise 'The "owner" of the lock is nil' if owner.nil?
205
246
  elapsed(@loog) do
206
247
  with_retries(max_tries: @retries) do
207
248
  checked(
@@ -220,6 +261,8 @@ class BazaRb
220
261
  # @param [String] name The name of the job on the server
221
262
  # @return [Integer] The ID of the job on the server
222
263
  def recent(name)
264
+ raise 'The "name" of the job is nil' if name.nil?
265
+ raise 'The "name" of the job may not be empty' if name.empty?
223
266
  job = 0
224
267
  elapsed(@loog) do
225
268
  ret =
@@ -241,6 +284,8 @@ class BazaRb
241
284
  # @param [String] name The name of the job on the server
242
285
  # @return [Boolean] TRUE if such name exists
243
286
  def name_exists?(name)
287
+ raise 'The "name" of the job is nil' if name.nil?
288
+ raise 'The "name" of the job may not be empty' if name.empty?
244
289
  exists = 0
245
290
  elapsed(@loog) do
246
291
  ret =
@@ -262,7 +307,10 @@ class BazaRb
262
307
  # @param [String] jname The name of the job on the server
263
308
  # @param [String] file The file name
264
309
  def durable_place(jname, file)
265
- raise "File '#{file}' is absent" unless File.exist?(file)
310
+ raise 'The "jname" of the durable is nil' if jname.nil?
311
+ raise 'The "jname" of the durable may not be empty' if jname.empty?
312
+ raise 'The "file" of the durable is nil' if file.nil?
313
+ raise "The file '#{file}' is absent" unless File.exist?(file)
266
314
  id = nil
267
315
  elapsed(@loog) do
268
316
  ret =
@@ -283,7 +331,7 @@ class BazaRb
283
331
  )
284
332
  end
285
333
  id = ret.headers['X-Zerocracy-DurableId'].to_i
286
- throw :"Durable ##{id} placed for job \"#{jname}\" at #{@host}"
334
+ throw :"Durable ##{id} (#{file}) placed for job \"#{jname}\" at #{@host}"
287
335
  end
288
336
  id
289
337
  end
@@ -292,7 +340,10 @@ class BazaRb
292
340
  # @param [Integer] id The ID of the durable
293
341
  # @param [String] file The file to upload
294
342
  def durable_save(id, file)
295
- raise "File '#{file}' is absent" unless File.exist?(file)
343
+ raise 'The ID of the durable is nil' if id.nil?
344
+ raise 'The ID of the durable must be a positive integer' unless id.positive?
345
+ raise 'The "file" of the durable is nil' if file.nil?
346
+ raise "The file '#{file}' is absent" unless File.exist?(file)
296
347
  elapsed(@loog) do
297
348
  with_retries(max_tries: @retries) do
298
349
  checked(
@@ -313,6 +364,9 @@ class BazaRb
313
364
  # @param [Integer] id The ID of the durable
314
365
  # @param [String] file The file to upload
315
366
  def durable_load(id, file)
367
+ raise 'The ID of the durable is nil' if id.nil?
368
+ raise 'The ID of the durable must be a positive integer' unless id.positive?
369
+ raise 'The "file" of the durable is nil' if file.nil?
316
370
  FileUtils.mkdir_p(File.dirname(file))
317
371
  elapsed(@loog) do
318
372
  File.open(file, 'wb') do |f|
@@ -341,6 +395,10 @@ class BazaRb
341
395
  # @param [Integer] id The ID of the durable
342
396
  # @param [String] owner The owner of the lock
343
397
  def durable_lock(id, owner)
398
+ raise 'The ID of the durable is nil' if id.nil?
399
+ raise 'The ID of the durable must be a positive integer' unless id.positive?
400
+ raise 'The "owner" of the lock is nil' if owner.nil?
401
+ raise 'The "owner" of the lock may not be empty' if owner.empty?
344
402
  elapsed(@loog) do
345
403
  with_retries(max_tries: @retries) do
346
404
  checked(
@@ -359,6 +417,10 @@ class BazaRb
359
417
  # @param [Integer] id The ID of the durable
360
418
  # @param [String] owner The owner of the lock
361
419
  def durable_unlock(id, owner)
420
+ raise 'The ID of the durable is nil' if id.nil?
421
+ raise 'The ID of the durable must be a positive integer' unless id.positive?
422
+ raise 'The "owner" of the lock is nil' if owner.nil?
423
+ raise 'The "owner" of the lock may not be empty' if owner.empty?
362
424
  elapsed(@loog) do
363
425
  with_retries(max_tries: @retries) do
364
426
  checked(
@@ -428,7 +490,12 @@ class BazaRb
428
490
  allowed = [allowed] unless allowed.is_a?(Array)
429
491
  mtd = (ret.request.original_options[:method] || '???').upcase
430
492
  url = ret.effective_url
431
- log = "#{mtd} #{url} -> #{ret.code}"
493
+ if ret.return_code == :operation_timedout
494
+ msg = "#{mtd} #{url} timed out in #{ret.total_time}s"
495
+ @loog.debug(msg)
496
+ raise msg
497
+ end
498
+ log = "#{mtd} #{url} -> #{ret.code} (#{format('%0.2f', ret.total_time)}s)"
432
499
  if allowed.include?(ret.code)
433
500
  @loog.debug(log)
434
501
  return ret
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.6
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