judges 0.3.0 ā 0.4.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 +4 -4
- data/Gemfile.lock +12 -10
- data/judges.gemspec +4 -3
- data/lib/judges/baza.rb +39 -28
- data/lib/judges/commands/update.rb +49 -20
- data/lib/judges.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc71c6f27206802eb89caac6ea4cf95558c5f36f484efea771e5ad5c442084d
|
4
|
+
data.tar.gz: 717c6de821765a54a916dc2eabafaf63827fd5a522584c7af866f5beea5475c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 895ea9f8d9b1527113c1a33d1c5e5a5d18b16994d00593d7f3eaf5c135c9a9eb9787c7ca969bcbced5b025eef8ff03e3927ecc90d3ee0738b9cee3cf1b948799
|
7
|
+
data.tar.gz: 2c86328e14c85f7685fb46b8cf78bcac87058725db51b57ca447186c61cbf5650dee93570c7000c11105792a14d8b8879d54e861325c1f12a97f200b09e33bb3
|
data/Gemfile.lock
CHANGED
@@ -9,14 +9,15 @@ PATH
|
|
9
9
|
iri (~> 0.8)
|
10
10
|
loog (~> 0.2)
|
11
11
|
nokogiri (~> 1.10)
|
12
|
+
retries (~> 0.0)
|
12
13
|
typhoeus (~> 1.3)
|
13
14
|
|
14
15
|
GEM
|
15
16
|
remote: https://rubygems.org/
|
16
17
|
specs:
|
17
|
-
actionpack (7.1.3.
|
18
|
-
actionview (= 7.1.3.
|
19
|
-
activesupport (= 7.1.3.
|
18
|
+
actionpack (7.1.3.4)
|
19
|
+
actionview (= 7.1.3.4)
|
20
|
+
activesupport (= 7.1.3.4)
|
20
21
|
nokogiri (>= 1.8.5)
|
21
22
|
racc
|
22
23
|
rack (>= 2.2.4)
|
@@ -24,13 +25,13 @@ GEM
|
|
24
25
|
rack-test (>= 0.6.3)
|
25
26
|
rails-dom-testing (~> 2.2)
|
26
27
|
rails-html-sanitizer (~> 1.6)
|
27
|
-
actionview (7.1.3.
|
28
|
-
activesupport (= 7.1.3.
|
28
|
+
actionview (7.1.3.4)
|
29
|
+
activesupport (= 7.1.3.4)
|
29
30
|
builder (~> 3.1)
|
30
31
|
erubi (~> 1.11)
|
31
32
|
rails-dom-testing (~> 2.2)
|
32
33
|
rails-html-sanitizer (~> 1.6)
|
33
|
-
activesupport (7.1.3.
|
34
|
+
activesupport (7.1.3.4)
|
34
35
|
base64
|
35
36
|
bigdecimal
|
36
37
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
@@ -84,7 +85,7 @@ GEM
|
|
84
85
|
erubi (1.12.0)
|
85
86
|
ethon (0.16.0)
|
86
87
|
ffi (>= 1.15.0)
|
87
|
-
factbase (0.0.
|
88
|
+
factbase (0.0.42)
|
88
89
|
json (~> 2.7)
|
89
90
|
loog (~> 0.2)
|
90
91
|
nokogiri (~> 1.10)
|
@@ -153,9 +154,9 @@ GEM
|
|
153
154
|
rails-html-sanitizer (1.6.0)
|
154
155
|
loofah (~> 2.21)
|
155
156
|
nokogiri (~> 1.14)
|
156
|
-
railties (7.1.3.
|
157
|
-
actionpack (= 7.1.3.
|
158
|
-
activesupport (= 7.1.3.
|
157
|
+
railties (7.1.3.4)
|
158
|
+
actionpack (= 7.1.3.4)
|
159
|
+
activesupport (= 7.1.3.4)
|
159
160
|
irb
|
160
161
|
rackup (>= 1.0.0)
|
161
162
|
rake (>= 12.2)
|
@@ -168,6 +169,7 @@ GEM
|
|
168
169
|
regexp_parser (2.9.2)
|
169
170
|
reline (0.5.8)
|
170
171
|
io-console (~> 0.5)
|
172
|
+
retries (0.0.5)
|
171
173
|
rexml (3.2.8)
|
172
174
|
strscan (>= 3.0.9)
|
173
175
|
rspec-core (3.13.0)
|
data/judges.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
27
|
s.required_ruby_version = '>=3.2'
|
28
28
|
s.name = 'judges'
|
29
|
-
s.version = '0.
|
29
|
+
s.version = '0.4.0'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Command-Line Tool for a Factbase'
|
32
32
|
s.description =
|
@@ -42,13 +42,14 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
43
43
|
s.rdoc_options = ['--charset=UTF-8']
|
44
44
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
45
|
-
s.add_runtime_dependency 'backtrace', '~>
|
45
|
+
s.add_runtime_dependency 'backtrace', '~>0.3'
|
46
46
|
s.add_runtime_dependency 'concurrent-ruby', '1.2.3'
|
47
47
|
s.add_runtime_dependency 'factbase', '~>0.0'
|
48
48
|
s.add_runtime_dependency 'gli', '~>2.21'
|
49
49
|
s.add_runtime_dependency 'iri', '~>0.8'
|
50
50
|
s.add_runtime_dependency 'loog', '~>0.2'
|
51
|
-
s.add_runtime_dependency 'nokogiri', '~>
|
51
|
+
s.add_runtime_dependency 'nokogiri', '~>1.10'
|
52
|
+
s.add_runtime_dependency 'retries', '~>0.0'
|
52
53
|
s.add_runtime_dependency 'typhoeus', '~>1.3'
|
53
54
|
s.metadata['rubygems_mfa_required'] = 'true'
|
54
55
|
end
|
data/lib/judges/baza.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'typhoeus'
|
24
|
+
require 'retries'
|
24
25
|
require 'iri'
|
25
26
|
require 'loog'
|
26
27
|
require_relative '../judges'
|
@@ -45,17 +46,20 @@ class Judges::Baza
|
|
45
46
|
def push(name, data)
|
46
47
|
id = 0
|
47
48
|
elapsed(@loog) do
|
48
|
-
ret =
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
ret = with_retries do
|
50
|
+
checked(
|
51
|
+
Typhoeus::Request.put(
|
52
|
+
home.append('push').append(name).to_s,
|
53
|
+
body: data,
|
54
|
+
headers: headers.merge(
|
55
|
+
'Content-Type' => 'application/octet-stream',
|
56
|
+
'Content-Length' => data.size
|
57
|
+
),
|
58
|
+
connecttimeout: @timeout,
|
59
|
+
timeout: @timeout
|
60
|
+
)
|
61
|
+
)
|
62
|
+
end
|
59
63
|
id = ret.body.to_i
|
60
64
|
throw :"Pushed #{data.size} bytes to #{@host}, job ID is ##{id}"
|
61
65
|
end
|
@@ -79,7 +83,7 @@ class Judges::Baza
|
|
79
83
|
f.write(chunk)
|
80
84
|
end
|
81
85
|
request.run
|
82
|
-
|
86
|
+
checked(request.response)
|
83
87
|
end
|
84
88
|
data = File.binread(file)
|
85
89
|
throw :"Pulled #{data.size} bytes of job ##{id} factbase at #{@host}"
|
@@ -92,11 +96,14 @@ class Judges::Baza
|
|
92
96
|
def finished?(id)
|
93
97
|
finished = false
|
94
98
|
elapsed(@loog) do
|
95
|
-
ret =
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
ret = with_retries do
|
100
|
+
checked(
|
101
|
+
Typhoeus::Request.get(
|
102
|
+
home.append('finished').append(id).to_s,
|
103
|
+
headers:
|
104
|
+
)
|
105
|
+
)
|
106
|
+
end
|
100
107
|
finished = ret.body == 'yes'
|
101
108
|
throw :"The job ##{id} is #{finished ? '' : 'not yet '}finished at #{@host}"
|
102
109
|
end
|
@@ -106,11 +113,14 @@ class Judges::Baza
|
|
106
113
|
def recent(name)
|
107
114
|
job = 0
|
108
115
|
elapsed(@loog) do
|
109
|
-
ret =
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
116
|
+
ret = with_retries do
|
117
|
+
checked(
|
118
|
+
Typhoeus::Request.get(
|
119
|
+
home.append('recent').append("#{name}.txt").to_s,
|
120
|
+
headers:
|
121
|
+
)
|
122
|
+
)
|
123
|
+
end
|
114
124
|
job = ret.body.to_i
|
115
125
|
throw :"The recent \"#{name}\" job's ID is ##{job} at #{@host}"
|
116
126
|
end
|
@@ -120,11 +130,12 @@ class Judges::Baza
|
|
120
130
|
def name_exists?(name)
|
121
131
|
exists = 0
|
122
132
|
elapsed(@loog) do
|
123
|
-
ret =
|
124
|
-
|
125
|
-
|
133
|
+
ret = checked(
|
134
|
+
Typhoeus::Request.get(
|
135
|
+
home.append('exists').append(name).to_s,
|
136
|
+
headers:
|
137
|
+
)
|
126
138
|
)
|
127
|
-
check_code(ret)
|
128
139
|
exists = ret.body == 'yes'
|
129
140
|
throw :"The name \"#{name}\" #{exists ? 'exists' : "doesn't exist"} at #{@host}"
|
130
141
|
end
|
@@ -148,14 +159,14 @@ class Judges::Baza
|
|
148
159
|
.scheme(@ssl ? 'https' : 'http')
|
149
160
|
end
|
150
161
|
|
151
|
-
def
|
162
|
+
def checked(ret, allowed = [200])
|
152
163
|
allowed = [allowed] unless allowed.is_a?(Array)
|
153
164
|
mtd = (ret.request.original_options[:method] || '???').upcase
|
154
165
|
url = ret.effective_url
|
155
166
|
log = "#{mtd} #{url} -> #{ret.code}"
|
156
167
|
if allowed.include?(ret.code)
|
157
168
|
@loog.debug(log)
|
158
|
-
return
|
169
|
+
return ret
|
159
170
|
end
|
160
171
|
@loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}")
|
161
172
|
msg =
|
@@ -56,9 +56,9 @@ class Judges::Update
|
|
56
56
|
if c > 1
|
57
57
|
@loog.info("\n\nStarting cycle ##{c}#{opts['max-cycles'] ? " (out of #{opts['max-cycles']})" : ''}...")
|
58
58
|
end
|
59
|
-
|
59
|
+
churn = cycle(opts, judges, fb, options)
|
60
60
|
impex.export(fb)
|
61
|
-
if
|
61
|
+
if churn.zero?
|
62
62
|
@loog.info("The update cycle ##{c} has made no changes to the factbase, let's stop")
|
63
63
|
break
|
64
64
|
end
|
@@ -66,36 +66,50 @@ class Judges::Update
|
|
66
66
|
@loog.info("Too many cycles already, as set by --max-cycles=#{opts['max-cycles']}, breaking")
|
67
67
|
break
|
68
68
|
end
|
69
|
-
@loog.info(
|
70
|
-
"By #{diff.abs} fact(s) the factbase " \
|
71
|
-
"#{diff.positive? ? 'increased' : 'decreased'} " \
|
72
|
-
"its size at the cycle ##{c}"
|
73
|
-
)
|
69
|
+
@loog.info("At the cycle #{c}, the factbase was modified by #{churn} fact(s)")
|
74
70
|
end
|
75
71
|
throw :"Update finished in #{c} cycle(s), #{format('+%d', fb.size - before)} fact(s)"
|
76
72
|
end
|
77
73
|
end
|
78
74
|
|
75
|
+
# How many facts were modified.
|
76
|
+
class Churn
|
77
|
+
attr_reader :added, :removed
|
78
|
+
|
79
|
+
def initialize(added, removed)
|
80
|
+
@added = added
|
81
|
+
@removed = removed
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_s
|
85
|
+
"#{format('+%d', @added)}/#{format('+%d', -@removed)}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def zero?
|
89
|
+
@added.zero? && @removed.zero?
|
90
|
+
end
|
91
|
+
|
92
|
+
def +(other)
|
93
|
+
Churn.new(@added + other.added, @removed + other.removed)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
79
97
|
private
|
80
98
|
|
99
|
+
# Run all judges in a full cycle, one by one.
|
100
|
+
# @return [Churn] How many modifications have been made
|
81
101
|
def cycle(opts, judges, fb, options)
|
82
102
|
errors = []
|
83
|
-
|
103
|
+
churn = Churn.new(0, 0)
|
84
104
|
global = {}
|
85
105
|
elapsed(@loog) do
|
86
106
|
done = judges.each_with_index do |p, i|
|
87
|
-
local = {}
|
88
107
|
@loog.info("\nš Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
errors << p.script
|
95
|
-
end
|
96
|
-
after = fb.size
|
97
|
-
@loog.info("š The judge #{p.dir.to_rel} added #{after - before} facts") if after > before
|
98
|
-
diff += after - before
|
108
|
+
churn += one_judge(fb, p, global, options)
|
109
|
+
@loog.info("š The judge #{p.name} modified #{churn} facts")
|
110
|
+
rescue StandardError, SyntaxError => e
|
111
|
+
@loog.warn(Backtrace.new(e))
|
112
|
+
errors << p.script
|
99
113
|
end
|
100
114
|
throw :"š #{done} judge(s) processed" if errors.empty?
|
101
115
|
throw :"ā #{done} judge(s) processed with #{errors.size} errors"
|
@@ -104,6 +118,21 @@ class Judges::Update
|
|
104
118
|
raise "Failed to update correctly (#{errors.size} errors)" unless opts['quiet']
|
105
119
|
@loog.info('Not failing because of the --quiet flag provided')
|
106
120
|
end
|
107
|
-
|
121
|
+
churn
|
122
|
+
end
|
123
|
+
|
124
|
+
# Run a single judge.
|
125
|
+
# @return [Churn] How many modifications have been made
|
126
|
+
def one_judge(fb, judge, global, options)
|
127
|
+
local = {}
|
128
|
+
before = fb.size
|
129
|
+
judge.run(fb, global, local, options)
|
130
|
+
after = fb.size
|
131
|
+
diff = after - before
|
132
|
+
if diff.positive?
|
133
|
+
Churn.new(diff, 0)
|
134
|
+
else
|
135
|
+
Churn.new(0, diff)
|
136
|
+
end
|
108
137
|
end
|
109
138
|
end
|
data/lib/judges.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: judges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
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-06-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: retries
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: typhoeus
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|