baza.rb 0.10.2 → 0.11.1
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/Gemfile +1 -0
- data/Gemfile.lock +53 -41
- data/Rakefile +1 -0
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +69 -66
- 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: 61125f85202d4fff1512986b6d908cddf4d34154b7d0251808aed552e3710fe4
|
|
4
|
+
data.tar.gz: d7f2af72be1e37db02b235ee251b53c2a6f005fdb52bed0020a389027800c62a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad169d4883e99abacc56de890cde937e6faeff3fd690aa370584b63c10987aa8804ac6c7b15df86de39580b3e55d498bf2834c522b0d8fe58e6fa87add564220
|
|
7
|
+
data.tar.gz: 35f78d75de7e884d880ac85a56928596bad609c29211b8ec13bf6fa1d666702a4500b28ad14ab2c631b4b738e8d7d4de79cf69f00944756fce5c7153a22ce2e1
|
data/Gemfile
CHANGED
|
@@ -18,6 +18,7 @@ gem 'rack', '~>3.1', require: false
|
|
|
18
18
|
gem 'rackup', '~>2.2', require: false
|
|
19
19
|
gem 'rake', '~>13.2', require: false
|
|
20
20
|
gem 'random-port', '~>0.7', require: false
|
|
21
|
+
gem 'rdoc', '6.16.0', require: false # GPL
|
|
21
22
|
gem 'rubocop', '~>1.73', require: false
|
|
22
23
|
gem 'rubocop-minitest', '~>0.38', require: false
|
|
23
24
|
gem 'rubocop-performance', '~>1.23', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -17,26 +17,28 @@ PATH
|
|
|
17
17
|
GEM
|
|
18
18
|
remote: https://rubygems.org/
|
|
19
19
|
specs:
|
|
20
|
-
addressable (2.8.
|
|
21
|
-
public_suffix (>= 2.0.2, <
|
|
20
|
+
addressable (2.8.8)
|
|
21
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
22
22
|
ansi (1.5.0)
|
|
23
23
|
ast (2.4.3)
|
|
24
24
|
backtrace (0.4.1)
|
|
25
25
|
base64 (0.3.0)
|
|
26
|
-
bigdecimal (3.
|
|
26
|
+
bigdecimal (3.3.1)
|
|
27
27
|
builder (3.3.0)
|
|
28
|
-
crack (1.0.
|
|
28
|
+
crack (1.0.1)
|
|
29
29
|
bigdecimal
|
|
30
30
|
rexml
|
|
31
|
+
date (3.5.0)
|
|
31
32
|
decoor (0.1.0)
|
|
32
33
|
docile (1.4.1)
|
|
33
34
|
elapsed (0.2.0)
|
|
34
35
|
loog (~> 0.6)
|
|
35
36
|
tago (~> 0.1)
|
|
36
37
|
ellipsized (0.3.0)
|
|
38
|
+
erb (6.0.0)
|
|
37
39
|
ethon (0.15.0)
|
|
38
40
|
ffi (>= 1.15.0)
|
|
39
|
-
factbase (0.
|
|
41
|
+
factbase (0.17.0)
|
|
40
42
|
backtrace (~> 0.4)
|
|
41
43
|
decoor (~> 0.1)
|
|
42
44
|
ellipsized (~> 0.3)
|
|
@@ -47,7 +49,7 @@ GEM
|
|
|
47
49
|
others (~> 0.1)
|
|
48
50
|
tago (~> 0.1)
|
|
49
51
|
yaml (~> 0.3)
|
|
50
|
-
faraday (2.
|
|
52
|
+
faraday (2.14.0)
|
|
51
53
|
faraday-net_http (>= 2.0, < 3.5)
|
|
52
54
|
json
|
|
53
55
|
logger
|
|
@@ -55,8 +57,8 @@ GEM
|
|
|
55
57
|
faraday (>= 0.8)
|
|
56
58
|
faraday-multipart (1.1.1)
|
|
57
59
|
multipart-post (~> 2.0)
|
|
58
|
-
faraday-net_http (3.4.
|
|
59
|
-
net-http (
|
|
60
|
+
faraday-net_http (3.4.2)
|
|
61
|
+
net-http (~> 0.5)
|
|
60
62
|
faraday-retry (2.3.2)
|
|
61
63
|
faraday (~> 2.0)
|
|
62
64
|
ffi (1.17.2-arm64-darwin)
|
|
@@ -64,14 +66,14 @@ GEM
|
|
|
64
66
|
ffi (1.17.2-x86_64-darwin)
|
|
65
67
|
ffi (1.17.2-x86_64-linux-gnu)
|
|
66
68
|
hashdiff (1.2.1)
|
|
67
|
-
iri (0.11.
|
|
68
|
-
json (2.
|
|
69
|
+
iri (0.11.3)
|
|
70
|
+
json (2.16.0)
|
|
69
71
|
language_server-protocol (3.17.0.5)
|
|
70
72
|
lint_roller (1.1.0)
|
|
71
73
|
logger (1.7.0)
|
|
72
74
|
loog (0.6.1)
|
|
73
75
|
logger (~> 1.0)
|
|
74
|
-
minitest (5.
|
|
76
|
+
minitest (5.26.2)
|
|
75
77
|
minitest-reporters (1.7.1)
|
|
76
78
|
ansi
|
|
77
79
|
builder
|
|
@@ -80,37 +82,40 @@ GEM
|
|
|
80
82
|
multipart-post (2.4.1)
|
|
81
83
|
mustermann (3.0.4)
|
|
82
84
|
ruby2_keywords (~> 0.0.1)
|
|
83
|
-
net-http (0.
|
|
84
|
-
uri
|
|
85
|
-
nio4r (2.7.
|
|
86
|
-
nokogiri (1.18.
|
|
85
|
+
net-http (0.8.0)
|
|
86
|
+
uri (>= 0.11.1)
|
|
87
|
+
nio4r (2.7.5)
|
|
88
|
+
nokogiri (1.18.10-arm64-darwin)
|
|
87
89
|
racc (~> 1.4)
|
|
88
|
-
nokogiri (1.18.
|
|
90
|
+
nokogiri (1.18.10-x64-mingw-ucrt)
|
|
89
91
|
racc (~> 1.4)
|
|
90
|
-
nokogiri (1.18.
|
|
92
|
+
nokogiri (1.18.10-x86_64-darwin)
|
|
91
93
|
racc (~> 1.4)
|
|
92
|
-
nokogiri (1.18.
|
|
94
|
+
nokogiri (1.18.10-x86_64-linux-gnu)
|
|
93
95
|
racc (~> 1.4)
|
|
94
96
|
online (0.1.0)
|
|
95
97
|
timeout (~> 0.4)
|
|
96
98
|
os (1.1.4)
|
|
97
99
|
others (0.1.1)
|
|
98
100
|
parallel (1.27.0)
|
|
99
|
-
parser (3.3.
|
|
101
|
+
parser (3.3.10.0)
|
|
100
102
|
ast (~> 2.4.1)
|
|
101
103
|
racc
|
|
102
|
-
prism (1.
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
prism (1.6.0)
|
|
105
|
+
psych (5.2.6)
|
|
106
|
+
date
|
|
107
|
+
stringio
|
|
108
|
+
public_suffix (7.0.0)
|
|
109
|
+
puma (7.1.0)
|
|
105
110
|
nio4r (~> 2.0)
|
|
106
|
-
qbash (0.4.
|
|
111
|
+
qbash (0.4.8)
|
|
107
112
|
backtrace (> 0)
|
|
108
113
|
elapsed (> 0)
|
|
109
114
|
loog (> 0)
|
|
110
115
|
tago (> 0)
|
|
111
116
|
racc (1.8.1)
|
|
112
|
-
rack (3.2.
|
|
113
|
-
rack-protection (4.
|
|
117
|
+
rack (3.2.4)
|
|
118
|
+
rack-protection (4.2.1)
|
|
114
119
|
base64 (>= 0.1.0)
|
|
115
120
|
logger (>= 1.6.0)
|
|
116
121
|
rack (>= 3.0.0, < 4)
|
|
@@ -120,13 +125,17 @@ GEM
|
|
|
120
125
|
rackup (2.2.1)
|
|
121
126
|
rack (>= 3)
|
|
122
127
|
rainbow (3.1.1)
|
|
123
|
-
rake (13.3.
|
|
124
|
-
random-port (0.7.
|
|
125
|
-
tago (
|
|
126
|
-
|
|
128
|
+
rake (13.3.1)
|
|
129
|
+
random-port (0.7.6)
|
|
130
|
+
tago (~> 0.0)
|
|
131
|
+
rdoc (6.16.0)
|
|
132
|
+
erb
|
|
133
|
+
psych (>= 4.0.0)
|
|
134
|
+
tsort
|
|
135
|
+
regexp_parser (2.11.3)
|
|
127
136
|
retries (0.0.5)
|
|
128
137
|
rexml (3.4.4)
|
|
129
|
-
rubocop (1.
|
|
138
|
+
rubocop (1.81.7)
|
|
130
139
|
json (~> 2.3)
|
|
131
140
|
language_server-protocol (~> 3.17.0.2)
|
|
132
141
|
lint_roller (~> 1.1.0)
|
|
@@ -134,20 +143,20 @@ GEM
|
|
|
134
143
|
parser (>= 3.3.0.2)
|
|
135
144
|
rainbow (>= 2.2.2, < 4.0)
|
|
136
145
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
137
|
-
rubocop-ast (>= 1.
|
|
146
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
138
147
|
ruby-progressbar (~> 1.7)
|
|
139
148
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
140
|
-
rubocop-ast (1.
|
|
149
|
+
rubocop-ast (1.48.0)
|
|
141
150
|
parser (>= 3.3.7.2)
|
|
142
151
|
prism (~> 1.4)
|
|
143
152
|
rubocop-minitest (0.38.2)
|
|
144
153
|
lint_roller (~> 1.1)
|
|
145
154
|
rubocop (>= 1.75.0, < 2.0)
|
|
146
155
|
rubocop-ast (>= 1.38.0, < 2.0)
|
|
147
|
-
rubocop-performance (1.26.
|
|
156
|
+
rubocop-performance (1.26.1)
|
|
148
157
|
lint_roller (~> 1.1)
|
|
149
158
|
rubocop (>= 1.75.0, < 2.0)
|
|
150
|
-
rubocop-ast (>= 1.
|
|
159
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
151
160
|
rubocop-rake (0.7.1)
|
|
152
161
|
lint_roller (~> 1.1)
|
|
153
162
|
rubocop (>= 1.72.1)
|
|
@@ -162,28 +171,30 @@ GEM
|
|
|
162
171
|
simplecov (~> 0.19)
|
|
163
172
|
simplecov-html (0.13.2)
|
|
164
173
|
simplecov_json_formatter (0.1.4)
|
|
165
|
-
sinatra (4.
|
|
174
|
+
sinatra (4.2.1)
|
|
166
175
|
logger (>= 1.6.0)
|
|
167
176
|
mustermann (~> 3.0)
|
|
168
177
|
rack (>= 3.0.0, < 4)
|
|
169
|
-
rack-protection (= 4.
|
|
178
|
+
rack-protection (= 4.2.1)
|
|
170
179
|
rack-session (>= 2.0.0, < 3)
|
|
171
180
|
tilt (~> 2.0)
|
|
172
|
-
|
|
181
|
+
stringio (3.1.8)
|
|
182
|
+
tago (0.4.0)
|
|
173
183
|
tilt (2.6.1)
|
|
174
|
-
timeout (0.4.
|
|
184
|
+
timeout (0.4.4)
|
|
185
|
+
tsort (0.2.0)
|
|
175
186
|
typhoeus (1.5.0)
|
|
176
187
|
ethon (>= 0.9.0, < 0.16.0)
|
|
177
188
|
unicode-display_width (3.2.0)
|
|
178
189
|
unicode-emoji (~> 4.1)
|
|
179
190
|
unicode-emoji (4.1.0)
|
|
180
|
-
uri (1.
|
|
191
|
+
uri (1.1.1)
|
|
181
192
|
wait_for (0.1.1)
|
|
182
|
-
webmock (3.
|
|
193
|
+
webmock (3.26.1)
|
|
183
194
|
addressable (>= 2.8.0)
|
|
184
195
|
crack (>= 0.3.2)
|
|
185
196
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
186
|
-
webrick (1.9.
|
|
197
|
+
webrick (1.9.2)
|
|
187
198
|
yaml (0.4.0)
|
|
188
199
|
yard (0.9.37)
|
|
189
200
|
|
|
@@ -210,6 +221,7 @@ DEPENDENCIES
|
|
|
210
221
|
rackup (~> 2.2)
|
|
211
222
|
rake (~> 13.2)
|
|
212
223
|
random-port (~> 0.7)
|
|
224
|
+
rdoc (= 6.16.0)
|
|
213
225
|
rubocop (~> 1.73)
|
|
214
226
|
rubocop-minitest (~> 0.38)
|
|
215
227
|
rubocop-performance (~> 1.23)
|
data/Rakefile
CHANGED
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
|
@@ -7,6 +7,7 @@ require 'base64'
|
|
|
7
7
|
require 'elapsed'
|
|
8
8
|
require 'fileutils'
|
|
9
9
|
require 'iri'
|
|
10
|
+
require 'logger'
|
|
10
11
|
require 'loog'
|
|
11
12
|
require 'retries'
|
|
12
13
|
require 'stringio'
|
|
@@ -78,7 +79,7 @@ class BazaRb
|
|
|
78
79
|
# @raise [ServerFailure] If authentication fails or server returns an error
|
|
79
80
|
def whoami
|
|
80
81
|
nick = nil
|
|
81
|
-
elapsed(@loog) do
|
|
82
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
82
83
|
ret = get(home.append('whoami'))
|
|
83
84
|
nick = ret.body
|
|
84
85
|
throw :"I know that I am @#{nick}, at #{@host}"
|
|
@@ -92,7 +93,7 @@ class BazaRb
|
|
|
92
93
|
# @raise [ServerFailure] If authentication fails or server returns an error
|
|
93
94
|
def balance
|
|
94
95
|
z = nil
|
|
95
|
-
elapsed(@loog) do
|
|
96
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
96
97
|
ret = get(home.append('account').append('balance'))
|
|
97
98
|
z = ret.body.to_f
|
|
98
99
|
throw :"The balance is Ƶ#{z}, at #{@host}"
|
|
@@ -102,21 +103,21 @@ class BazaRb
|
|
|
102
103
|
|
|
103
104
|
# Push factbase to the server to create a new job.
|
|
104
105
|
#
|
|
105
|
-
# @param [String]
|
|
106
|
+
# @param [String] pname The unique name of the product on the server
|
|
106
107
|
# @param [String] data The binary data to push to the server (factbase content)
|
|
107
108
|
# @param [Array<String>] meta List of metadata strings to attach to the job
|
|
108
109
|
# @param [Integer] chunk_size Maximum size of one chunk
|
|
109
110
|
# @raise [ServerFailure] If the push operation fails
|
|
110
|
-
def push(
|
|
111
|
-
raise 'The "name" of the job is nil' if
|
|
112
|
-
raise 'The "name" of the job may not be empty' if
|
|
111
|
+
def push(pname, data, meta, chunk_size: DEFAULT_CHUNK_SIZE)
|
|
112
|
+
raise 'The "name" of the job is nil' if pname.nil?
|
|
113
|
+
raise 'The "name" of the job may not be empty' if pname.empty?
|
|
113
114
|
raise 'The "data" of the job is nil' if data.nil?
|
|
114
115
|
raise 'The "meta" of the job is nil' if meta.nil?
|
|
115
|
-
elapsed(@loog) do
|
|
116
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
116
117
|
Tempfile.open do |file|
|
|
117
118
|
File.binwrite(file.path, data)
|
|
118
119
|
upload(
|
|
119
|
-
home.append('push').append(
|
|
120
|
+
home.append('push').append(pname),
|
|
120
121
|
file.path,
|
|
121
122
|
headers.merge(
|
|
122
123
|
'X-Zerocracy-Meta' => meta.map { |v| Base64.encode64(v).delete("\n") }.join(' ')
|
|
@@ -137,7 +138,7 @@ class BazaRb
|
|
|
137
138
|
raise 'The ID of the job is nil' if id.nil?
|
|
138
139
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
|
139
140
|
data = ''
|
|
140
|
-
elapsed(@loog) do
|
|
141
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
141
142
|
Tempfile.open do |file|
|
|
142
143
|
download(home.append('pull').append("#{id}.fb"), file.path)
|
|
143
144
|
data = File.binread(file)
|
|
@@ -156,7 +157,7 @@ class BazaRb
|
|
|
156
157
|
raise 'The ID of the job is nil' if id.nil?
|
|
157
158
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
|
158
159
|
fin = false
|
|
159
|
-
elapsed(@loog) do
|
|
160
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
160
161
|
ret = get(home.append('finished').append(id))
|
|
161
162
|
fin = ret.body == 'yes'
|
|
162
163
|
throw :"The job ##{id} is #{'not yet ' unless fin}finished at #{@host}#{" (#{ret.body.inspect})" unless fin}"
|
|
@@ -173,7 +174,7 @@ class BazaRb
|
|
|
173
174
|
raise 'The ID of the job is nil' if id.nil?
|
|
174
175
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
|
175
176
|
stdout = ''
|
|
176
|
-
elapsed(@loog) do
|
|
177
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
177
178
|
ret = get(home.append('stdout').append("#{id}.txt"))
|
|
178
179
|
stdout = ret.body
|
|
179
180
|
throw :"The stdout of the job ##{id} has #{stdout.split("\n").count} lines"
|
|
@@ -190,7 +191,7 @@ class BazaRb
|
|
|
190
191
|
raise 'The ID of the job is nil' if id.nil?
|
|
191
192
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
|
192
193
|
code = 0
|
|
193
|
-
elapsed(@loog) do
|
|
194
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
194
195
|
ret = get(home.append('exit').append("#{id}.txt"))
|
|
195
196
|
code = ret.body.to_i
|
|
196
197
|
throw :"The exit code of the job ##{id} is #{code}"
|
|
@@ -207,7 +208,7 @@ class BazaRb
|
|
|
207
208
|
raise 'The ID of the job is nil' if id.nil?
|
|
208
209
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
|
209
210
|
verdict = ''
|
|
210
|
-
elapsed(@loog) do
|
|
211
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
211
212
|
ret = get(home.append('jobs').append(id).append('verified.txt'))
|
|
212
213
|
verdict = ret.body
|
|
213
214
|
throw :"The verdict of the job ##{id} is #{verdict.inspect}"
|
|
@@ -217,41 +218,41 @@ class BazaRb
|
|
|
217
218
|
|
|
218
219
|
# Lock the name.
|
|
219
220
|
#
|
|
220
|
-
# @param [String]
|
|
221
|
+
# @param [String] pname The name of the product on the server
|
|
221
222
|
# @param [String] owner The owner of the lock (any string)
|
|
222
223
|
# @raise [RuntimeError] If the name is already locked
|
|
223
224
|
# @raise [ServerFailure] If the lock operation fails
|
|
224
|
-
def lock(
|
|
225
|
-
raise 'The "
|
|
226
|
-
raise 'The "
|
|
225
|
+
def lock(pname, owner)
|
|
226
|
+
raise 'The "pname" of the product is nil' if pname.nil?
|
|
227
|
+
raise 'The "pname" of the product may not be empty' if pname.empty?
|
|
227
228
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
|
228
|
-
elapsed(@loog) do
|
|
229
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
229
230
|
ret = post(
|
|
230
|
-
home.append('lock').append(
|
|
231
|
+
home.append('lock').append(pname),
|
|
231
232
|
{ 'owner' => owner },
|
|
232
233
|
[302, 409]
|
|
233
234
|
)
|
|
234
|
-
throw :"
|
|
235
|
-
raise "Failed to lock
|
|
235
|
+
throw :"Product name #{pname.inspect} locked at #{@host}" if ret.code == 302
|
|
236
|
+
raise "Failed to lock #{pname.inspect} product at #{@host}, it's already locked"
|
|
236
237
|
end
|
|
237
238
|
end
|
|
238
239
|
|
|
239
240
|
# Unlock the name.
|
|
240
241
|
#
|
|
241
|
-
# @param [String]
|
|
242
|
+
# @param [String] pname The name of the job on the server
|
|
242
243
|
# @param [String] owner The owner of the lock (any string)
|
|
243
244
|
# @raise [ServerFailure] If the unlock operation fails
|
|
244
|
-
def unlock(
|
|
245
|
-
raise 'The "
|
|
246
|
-
raise 'The "
|
|
245
|
+
def unlock(pname, owner)
|
|
246
|
+
raise 'The "pname" of the job is nil' if pname.nil?
|
|
247
|
+
raise 'The "pname" of the job may not be empty' if pname.empty?
|
|
247
248
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
|
248
249
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
|
249
|
-
elapsed(@loog) do
|
|
250
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
250
251
|
post(
|
|
251
|
-
home.append('unlock').append(
|
|
252
|
+
home.append('unlock').append(pname),
|
|
252
253
|
{ 'owner' => owner }
|
|
253
254
|
)
|
|
254
|
-
throw :"Job name
|
|
255
|
+
throw :"Job name #{pname.inspect} unlocked at #{@host}"
|
|
255
256
|
end
|
|
256
257
|
end
|
|
257
258
|
|
|
@@ -264,7 +265,7 @@ class BazaRb
|
|
|
264
265
|
raise 'The "name" of the job is nil' if name.nil?
|
|
265
266
|
raise 'The "name" of the job may not be empty' if name.empty?
|
|
266
267
|
job = nil
|
|
267
|
-
elapsed(@loog) do
|
|
268
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
268
269
|
ret = get(home.append('recent').append("#{name}.txt"))
|
|
269
270
|
job = ret.body.to_i
|
|
270
271
|
throw :"The recent \"#{name}\" job's ID is ##{job} at #{@host}"
|
|
@@ -274,16 +275,16 @@ class BazaRb
|
|
|
274
275
|
|
|
275
276
|
# Check whether the name of the job exists on the server.
|
|
276
277
|
#
|
|
277
|
-
# @param [String]
|
|
278
|
+
# @param [String] pname The name of the product on the server
|
|
278
279
|
# @return [Boolean] TRUE if such name exists
|
|
279
|
-
def name_exists?(
|
|
280
|
-
raise 'The "
|
|
281
|
-
raise 'The "
|
|
280
|
+
def name_exists?(pname)
|
|
281
|
+
raise 'The "pname" of the product is nil' if pname.nil?
|
|
282
|
+
raise 'The "pname" of the product may not be empty' if pname.empty?
|
|
282
283
|
exists = false
|
|
283
|
-
elapsed(@loog) do
|
|
284
|
-
ret = get(home.append('exists').append(
|
|
284
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
285
|
+
ret = get(home.append('exists').append(pname))
|
|
285
286
|
exists = ret.body == 'yes'
|
|
286
|
-
throw :"The name
|
|
287
|
+
throw :"The name #{pname.inspect} #{exists ? 'exists' : "doesn't exist"} at #{@host}"
|
|
287
288
|
end
|
|
288
289
|
exists
|
|
289
290
|
end
|
|
@@ -295,30 +296,31 @@ class BazaRb
|
|
|
295
296
|
# ignored. It is expected to use only small placeholder files, not real
|
|
296
297
|
# data.
|
|
297
298
|
#
|
|
298
|
-
# @param [String]
|
|
299
|
+
# @param [String] pname The name of the product on the server
|
|
299
300
|
# @param [String] file The path to the file to upload
|
|
300
301
|
# @return [Integer] The ID of the created durable
|
|
301
302
|
# @raise [ServerFailure] If the upload fails
|
|
302
|
-
def durable_place(
|
|
303
|
-
raise 'The "
|
|
304
|
-
raise 'The "
|
|
303
|
+
def durable_place(pname, file)
|
|
304
|
+
raise 'The "pname" of the durable is nil' if pname.nil?
|
|
305
|
+
raise 'The "pname" of the durable may not be empty' if pname.empty?
|
|
305
306
|
raise 'The "file" of the durable is nil' if file.nil?
|
|
306
307
|
raise "The file '#{file}' is absent" unless File.exist?(file)
|
|
307
308
|
if File.size(file) > 1024
|
|
308
309
|
raise "The file '#{file}' is too big (#{File.size(file)} bytes) for durable_place(), use durable_save() instead"
|
|
309
310
|
end
|
|
310
311
|
id = nil
|
|
311
|
-
elapsed(@loog) do
|
|
312
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
312
313
|
ret = post(
|
|
313
314
|
home.append('durables').append('place'),
|
|
314
315
|
{
|
|
315
|
-
'
|
|
316
|
+
'pname' => pname,
|
|
317
|
+
'jname' => pname,
|
|
316
318
|
'file' => File.basename(file),
|
|
317
319
|
'zip' => File.open(file, 'rb')
|
|
318
320
|
}
|
|
319
321
|
)
|
|
320
322
|
id = ret.headers['X-Zerocracy-DurableId'].to_i
|
|
321
|
-
throw :"Durable ##{id} (#{file}, #{File.size(file)} bytes) placed for job \"#{
|
|
323
|
+
throw :"Durable ##{id} (#{file}, #{File.size(file)} bytes) placed for job \"#{pname}\" at #{@host}"
|
|
322
324
|
end
|
|
323
325
|
id
|
|
324
326
|
end
|
|
@@ -335,7 +337,7 @@ class BazaRb
|
|
|
335
337
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
|
336
338
|
raise 'The "file" of the durable is nil' if file.nil?
|
|
337
339
|
raise "The file '#{file}' is absent" unless File.exist?(file)
|
|
338
|
-
elapsed(@loog) do
|
|
340
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
339
341
|
upload(home.append('durables').append(id), file, chunk_size:)
|
|
340
342
|
throw :"Durable ##{id} saved #{File.size(file)} bytes to #{@host}"
|
|
341
343
|
end
|
|
@@ -351,7 +353,7 @@ class BazaRb
|
|
|
351
353
|
raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
|
|
352
354
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
|
353
355
|
raise 'The "file" of the durable is nil' if file.nil?
|
|
354
|
-
elapsed(@loog) do
|
|
356
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
355
357
|
download(home.append('durables').append(id), file)
|
|
356
358
|
throw :"Durable ##{id} loaded #{File.size(file)} bytes from #{@host}"
|
|
357
359
|
end
|
|
@@ -368,7 +370,7 @@ class BazaRb
|
|
|
368
370
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
|
369
371
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
|
370
372
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
|
371
|
-
elapsed(@loog) do
|
|
373
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
372
374
|
post(
|
|
373
375
|
home.append('durables').append(id).append('lock'),
|
|
374
376
|
{ 'owner' => owner }
|
|
@@ -388,7 +390,7 @@ class BazaRb
|
|
|
388
390
|
raise 'The ID of the durable must be a positive integer' unless id.positive?
|
|
389
391
|
raise 'The "owner" of the lock is nil' if owner.nil?
|
|
390
392
|
raise 'The "owner" of the lock may not be empty' if owner.empty?
|
|
391
|
-
elapsed(@loog) do
|
|
393
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
392
394
|
post(
|
|
393
395
|
home.append('durables').append(id).append('unlock'),
|
|
394
396
|
{ 'owner' => owner }
|
|
@@ -399,22 +401,22 @@ class BazaRb
|
|
|
399
401
|
|
|
400
402
|
# Find a durable by job name and file name.
|
|
401
403
|
#
|
|
402
|
-
# @param [String]
|
|
404
|
+
# @param [String] pname The name of the job
|
|
403
405
|
# @param [String] file The file name
|
|
404
406
|
# @return [Integer, nil] The ID of the durable if found, nil if not found
|
|
405
|
-
def durable_find(
|
|
406
|
-
raise 'The "
|
|
407
|
-
raise 'The "
|
|
407
|
+
def durable_find(pname, file)
|
|
408
|
+
raise 'The "pname" is nil' if pname.nil?
|
|
409
|
+
raise 'The "pname" may not be empty' if pname.empty?
|
|
408
410
|
raise 'The "file" is nil' if file.nil?
|
|
409
411
|
raise 'The "file" may not be empty' if file.empty?
|
|
410
412
|
id = nil
|
|
411
|
-
elapsed(@loog) do
|
|
412
|
-
ret = get(home.append('durables').append('find').add(jname:, file:), [200, 404])
|
|
413
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
414
|
+
ret = get(home.append('durables').append('find').add(jname: pname, pname:, file:), [200, 404])
|
|
413
415
|
if ret.code == 200
|
|
414
416
|
id = ret.body.to_i
|
|
415
|
-
throw :"Found durable ##{id} for job \"#{
|
|
417
|
+
throw :"Found durable ##{id} for job \"#{pname}\" file \"#{file}\" at #{@host}"
|
|
416
418
|
else
|
|
417
|
-
throw :"Durable not found for job \"#{
|
|
419
|
+
throw :"Durable not found for job \"#{pname}\" file \"#{file}\" at #{@host}"
|
|
418
420
|
end
|
|
419
421
|
end
|
|
420
422
|
id
|
|
@@ -440,7 +442,7 @@ class BazaRb
|
|
|
440
442
|
'summary' => summary
|
|
441
443
|
}
|
|
442
444
|
body['job'] = job unless job.nil?
|
|
443
|
-
elapsed(@loog) do
|
|
445
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
444
446
|
ret = post(
|
|
445
447
|
home.append('account').append('transfer'),
|
|
446
448
|
body
|
|
@@ -467,7 +469,7 @@ class BazaRb
|
|
|
467
469
|
raise 'The "job" must be Integer' unless job.is_a?(Integer)
|
|
468
470
|
raise 'The "summary" is nil' if summary.nil?
|
|
469
471
|
id = nil
|
|
470
|
-
elapsed(@loog) do
|
|
472
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
471
473
|
ret = post(
|
|
472
474
|
home.append('account').append('fee'),
|
|
473
475
|
{
|
|
@@ -491,7 +493,7 @@ class BazaRb
|
|
|
491
493
|
# @raise [ServerFailure] If the pop operation fails
|
|
492
494
|
def pop(owner, zip)
|
|
493
495
|
success = false
|
|
494
|
-
elapsed(@loog) do
|
|
496
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
495
497
|
uri = home.append('pop').add(owner:)
|
|
496
498
|
ret = get(uri, [204, 302])
|
|
497
499
|
if ret.code == 204
|
|
@@ -518,7 +520,7 @@ class BazaRb
|
|
|
518
520
|
raise 'The ID of the job must be a positive integer' unless id.positive?
|
|
519
521
|
raise 'The "zip" of the job is nil' if zip.nil?
|
|
520
522
|
raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
|
|
521
|
-
elapsed(@loog) do
|
|
523
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
522
524
|
upload(home.append('finish').add(id:), zip)
|
|
523
525
|
throw :"Pushed #{File.size(zip)} bytes to #{@host}, finished job ##{id}"
|
|
524
526
|
end
|
|
@@ -530,15 +532,15 @@ class BazaRb
|
|
|
530
532
|
# for the given badge already exists, it's returned. Otherwise, the block
|
|
531
533
|
# is executed and its result is cached.
|
|
532
534
|
#
|
|
533
|
-
# @param [String]
|
|
535
|
+
# @param [String] pname Name of the product
|
|
534
536
|
# @param [String] badge Unique identifier for this valve/computation
|
|
535
537
|
# @param [String] why The reason/description for entering this valve
|
|
536
538
|
# @param [nil|Integer] job Optional job ID to associate with this valve
|
|
537
539
|
# @yield Block that computes the result if not cached
|
|
538
540
|
# @return [String] The cached result or newly computed result from the block
|
|
539
541
|
# @raise [ServerFailure] If the valve operation fails
|
|
540
|
-
def enter(
|
|
541
|
-
elapsed(@loog, good: "Entered valve #{badge} to #{
|
|
542
|
+
def enter(pname, badge, why, job)
|
|
543
|
+
elapsed(@loog, good: "Entered valve #{badge} to #{pname}") do
|
|
542
544
|
retry_it do
|
|
543
545
|
ret = get(home.append('valves').append('result').add(badge:), [200, 204])
|
|
544
546
|
return ret.body if ret.code == 200
|
|
@@ -548,7 +550,8 @@ class BazaRb
|
|
|
548
550
|
post(
|
|
549
551
|
uri,
|
|
550
552
|
{
|
|
551
|
-
'name' =>
|
|
553
|
+
'name' => pname,
|
|
554
|
+
'pname' => pname,
|
|
552
555
|
'badge' => badge,
|
|
553
556
|
'why' => why,
|
|
554
557
|
'result' => r.to_s
|
|
@@ -568,7 +571,7 @@ class BazaRb
|
|
|
568
571
|
# @raise [ServerFailure] If token retrieval fails
|
|
569
572
|
def csrf
|
|
570
573
|
token = nil
|
|
571
|
-
elapsed(@loog) do
|
|
574
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
572
575
|
token = get(home.append('csrf')).body
|
|
573
576
|
throw :"CSRF token retrieved (#{token.length} chars)"
|
|
574
577
|
end
|
|
@@ -792,7 +795,7 @@ class BazaRb
|
|
|
792
795
|
FileUtils.touch(file)
|
|
793
796
|
chunk = 0
|
|
794
797
|
blanks = [204, 302]
|
|
795
|
-
elapsed(@loog) do
|
|
798
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
796
799
|
loop do
|
|
797
800
|
slice = ''
|
|
798
801
|
ret = nil
|
|
@@ -877,7 +880,7 @@ class BazaRb
|
|
|
877
880
|
total = File.size(file)
|
|
878
881
|
chunk = 0
|
|
879
882
|
sent = 0
|
|
880
|
-
elapsed(@loog) do
|
|
883
|
+
elapsed(@loog, level: Logger::INFO) do
|
|
881
884
|
loop do
|
|
882
885
|
slice =
|
|
883
886
|
if total > chunk_size
|