zold 0.16.11 → 0.16.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/node/farm.rb +4 -36
- data/lib/zold/node/farmers.rb +3 -3
- data/lib/zold/node/front.rb +2 -2
- data/lib/zold/version.rb +1 -1
- data/test/node/test_farmers.rb +1 -1
- data/test/test__helper.rb +5 -1
- 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: b3c8beba4ea2ef38460a7107b2d1bf9d751f4dac69924ad31a8b87a771585349
|
4
|
+
data.tar.gz: a9cb982cbb48c63d6755f91251e95a8a72dc5a3dd68bf810001b8ded5994cdf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9d5e6df44283a6d75d49b75c5ecb5abb829059114699b4ddbd2e8629e1f76e306be5a64ce29c2f1fb2bf8f6508e7c21efa158325ee7186833d1689b8613d3c5
|
7
|
+
data.tar.gz: a6cc7024026e66a280af7e6410d9e10a1ea6bda8e7d1663e85630ad5077fa03b42991672cc69e3d7717f2e5244b56d571f56bcb2bd1c3b1e1da86f0161da137f
|
data/lib/zold/node/farm.rb
CHANGED
@@ -98,8 +98,7 @@ module Zold
|
|
98
98
|
end.join(', '),
|
99
99
|
cleanup: @cleanup.status,
|
100
100
|
pipeline: @pipeline.size,
|
101
|
-
best: best.map(&:to_mnemo).join(', ')
|
102
|
-
alive: @alive
|
101
|
+
best: best.map(&:to_mnemo).join(', ')
|
103
102
|
}
|
104
103
|
end
|
105
104
|
|
@@ -122,7 +121,6 @@ module Zold
|
|
122
121
|
@log.info("#{best.size} scores pre-loaded from #{@cache}, the best is: #{best[0]}")
|
123
122
|
end
|
124
123
|
cleanup(host, port, strength, threads)
|
125
|
-
@alive = true
|
126
124
|
@threads = (1..threads).map do |t|
|
127
125
|
Thread.new do
|
128
126
|
Thread.current.abort_on_exception = true
|
@@ -131,7 +129,6 @@ module Zold
|
|
131
129
|
VerboseThread.new(@log).run do
|
132
130
|
cycle(host, port, strength, threads)
|
133
131
|
end
|
134
|
-
break unless @alive
|
135
132
|
end
|
136
133
|
end
|
137
134
|
end
|
@@ -139,15 +136,6 @@ module Zold
|
|
139
136
|
Thread.current.abort_on_exception = true
|
140
137
|
Thread.current.name = 'cleanup'
|
141
138
|
loop do
|
142
|
-
max = 100
|
143
|
-
a = (0..max - 1).take_while do
|
144
|
-
sleep 0.01
|
145
|
-
@alive
|
146
|
-
end
|
147
|
-
unless a.count == max
|
148
|
-
@log.info("It's time to stop the cleanup thread (#{a.count} != #{max}, alive=#{@alive})...")
|
149
|
-
break
|
150
|
-
end
|
151
139
|
VerboseThread.new(@log).run(true) do
|
152
140
|
cleanup(host, port, strength, threads)
|
153
141
|
end
|
@@ -158,33 +146,14 @@ module Zold
|
|
158
146
|
begin
|
159
147
|
yield(self)
|
160
148
|
ensure
|
161
|
-
@
|
162
|
-
|
163
|
-
|
164
|
-
@threads.each { |t| finish(t) }
|
165
|
-
@log.info("Farm stopped in #{Age.new(start)} (threads=#{threads}, strength=#{strength})")
|
149
|
+
@cleanup.kill
|
150
|
+
@threads.each(&:kill)
|
151
|
+
@log.info("Farm stopped (threads=#{threads}, strength=#{strength})")
|
166
152
|
end
|
167
153
|
end
|
168
154
|
|
169
155
|
private
|
170
156
|
|
171
|
-
def finish(thread)
|
172
|
-
start = Time.now
|
173
|
-
@alive = false
|
174
|
-
@log.info("Attempting to terminate the thread \"#{thread.name}\" of the farm...")
|
175
|
-
loop do
|
176
|
-
delay = Time.now - start
|
177
|
-
if thread.join(0.1)
|
178
|
-
@log.info("Thread \"#{thread.name}\" peacefully finished in #{Age.new(start)}")
|
179
|
-
break
|
180
|
-
end
|
181
|
-
if delay > 1
|
182
|
-
thread.exit
|
183
|
-
@log.error("Thread \"#{thread.name}\" forcefully terminated after #{Age.new(start)}")
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
157
|
def cleanup(host, port, strength, threads)
|
189
158
|
scores = load
|
190
159
|
before = scores.map(&:value).max.to_i
|
@@ -200,7 +169,6 @@ module Zold
|
|
200
169
|
def cycle(host, port, strength, threads)
|
201
170
|
s = []
|
202
171
|
loop do
|
203
|
-
return unless @alive
|
204
172
|
begin
|
205
173
|
s << @pipeline.pop(true)
|
206
174
|
rescue ThreadError => _
|
data/lib/zold/node/farmers.rb
CHANGED
@@ -55,8 +55,8 @@ module Zold
|
|
55
55
|
'ruby',
|
56
56
|
Shellwords.escape(bin),
|
57
57
|
'--skip-upgrades',
|
58
|
-
|
59
|
-
|
58
|
+
"--info-thread=#{Shellwords.escape(Thread.current.name)}",
|
59
|
+
"--info-start=#{Time.now.utc.iso8601}",
|
60
60
|
'--low-priority',
|
61
61
|
'next',
|
62
62
|
Shellwords.escape(score)
|
@@ -100,7 +100,7 @@ for #{after.host}:#{after.port} in #{Age.new(start)}: #{after.suffixes}")
|
|
100
100
|
private
|
101
101
|
|
102
102
|
def kill(pid)
|
103
|
-
Process.kill('
|
103
|
+
Process.kill('KILL', pid)
|
104
104
|
@log.debug("Process ##{pid} killed")
|
105
105
|
rescue StandardError => e
|
106
106
|
@log.debug("No need to kill process ##{pid} since it's dead already: #{e.message}")
|
data/lib/zold/node/front.rb
CHANGED
@@ -189,7 +189,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
189
189
|
cpus: settings.zache.get(:cpus) do
|
190
190
|
Concurrent.processor_count
|
191
191
|
end,
|
192
|
-
memory: settings.zache.get(:
|
192
|
+
memory: settings.zache.get(:memory, lifetime: 5 * 60) do
|
193
193
|
require 'get_process_mem'
|
194
194
|
GetProcessMem.new.bytes.to_i
|
195
195
|
end,
|
@@ -405,7 +405,7 @@ in #{Age.new(@start, limit: 1)}")
|
|
405
405
|
|
406
406
|
get '/ps' do
|
407
407
|
content_type('text/plain')
|
408
|
-
`ps ax`
|
408
|
+
`ps ax | grep zold`
|
409
409
|
end
|
410
410
|
|
411
411
|
not_found do
|
data/lib/zold/version.rb
CHANGED
data/test/node/test_farmers.rb
CHANGED
@@ -38,7 +38,7 @@ class FarmersTest < Minitest::Test
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_calculates_large_score
|
41
|
-
log = TestLogger.new
|
41
|
+
log = TestLogger.new(test_log)
|
42
42
|
thread = Thread.start do
|
43
43
|
farmer = Zold::Farmers::Spawn.new(log: log)
|
44
44
|
farmer.up(Zold::Score.new(host: 'a', port: 1, invoice: 'NOPREFIX4@ffffffffffffffff', strength: 20))
|
data/test/test__helper.rb
CHANGED
@@ -64,19 +64,23 @@ module Minitest
|
|
64
64
|
|
65
65
|
class TestLogger
|
66
66
|
attr_accessor :msgs
|
67
|
-
def initialize
|
67
|
+
def initialize(log = Zold::Log::Quiet.new)
|
68
|
+
@log = log
|
68
69
|
@msgs = []
|
69
70
|
end
|
70
71
|
|
71
72
|
def info(msg)
|
73
|
+
@log.info(msg)
|
72
74
|
@msgs << msg
|
73
75
|
end
|
74
76
|
|
75
77
|
def debug(msg)
|
78
|
+
@log.debug(msg)
|
76
79
|
@msgs << msg
|
77
80
|
end
|
78
81
|
|
79
82
|
def error(msg)
|
83
|
+
@log.error(msg)
|
80
84
|
@msgs << msg
|
81
85
|
end
|
82
86
|
end
|