zold 0.16.19 → 0.16.20
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/farmers.rb +8 -3
- data/lib/zold/version.rb +1 -1
- data/test/node/test_farmers.rb +17 -0
- 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: fecaea03a1281af059406fd284d9b814fac0e4d0646ef6e65d8b4aacbf813169
|
4
|
+
data.tar.gz: 5e9a58d162b1333189e6346a25e2d24c411ec4bf3a3f074ab2c0a3d3e1185a57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a71a411222753fc52f30ae2e4c9f7e374832840430cedfde87f5572ee7f1a67f41365bc17ac8fb708feaeb77ac8ad9e4c8c7137f61568d0734ba845f1561a47
|
7
|
+
data.tar.gz: aad4fc840d9e5c87315f6a4d1c4997e326511eb94910c1aec9496b89e37ea7c7926b0ae55d69f31bc069d374a946eebf12c395060b168a992d2f9c03ddb5a809
|
data/lib/zold/node/farmers.rb
CHANGED
@@ -24,6 +24,7 @@ require 'open3'
|
|
24
24
|
require 'backtrace'
|
25
25
|
require 'zold/score'
|
26
26
|
require 'shellwords'
|
27
|
+
require 'posix/spawn'
|
27
28
|
require_relative '../log'
|
28
29
|
require_relative '../age'
|
29
30
|
|
@@ -48,6 +49,9 @@ module Zold
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def up(score)
|
52
|
+
if POSIX::Spawn::Child.new('ps', 'ax').out.include?(score.to_s.split(' ').take(4).join(' '))
|
53
|
+
raise "We are farming the score already: #{score}"
|
54
|
+
end
|
51
55
|
start = Time.now
|
52
56
|
bin = File.expand_path(File.join(File.dirname(__FILE__), '../../../bin/zold'))
|
53
57
|
raise "Zold binary not found at #{bin}" unless File.exist?(bin)
|
@@ -64,6 +68,7 @@ module Zold
|
|
64
68
|
].join(' ')
|
65
69
|
Open3.popen2e(cmd) do |stdin, stdout, thr|
|
66
70
|
Thread.current.thread_variable_set(:pid, thr.pid.to_s)
|
71
|
+
at_exit { kill(thr.pid, start) }
|
67
72
|
@log.debug("Scoring started in proc ##{thr.pid} \
|
68
73
|
for #{score.value}/#{score.strength} at #{score.host}:#{score.port}")
|
69
74
|
begin
|
@@ -93,16 +98,16 @@ for #{score.value}/#{score.strength} at #{score.host}:#{score.port}")
|
|
93
98
|
for #{after.host}:#{after.port} in #{Age.new(start)}: #{after.suffixes}")
|
94
99
|
after
|
95
100
|
ensure
|
96
|
-
kill(thr.pid)
|
101
|
+
kill(thr.pid, start)
|
97
102
|
end
|
98
103
|
end
|
99
104
|
end
|
100
105
|
|
101
106
|
private
|
102
107
|
|
103
|
-
def kill(pid)
|
108
|
+
def kill(pid, start)
|
104
109
|
Process.kill('KILL', pid)
|
105
|
-
@log.debug("Process ##{pid} killed")
|
110
|
+
@log.debug("Process ##{pid} killed after #{Age.new(start)} of activity")
|
106
111
|
rescue StandardError => e
|
107
112
|
@log.debug("No need to kill process ##{pid} since it's dead already: #{e.message}")
|
108
113
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/node/test_farmers.rb
CHANGED
@@ -58,4 +58,21 @@ class FarmersTest < Zold::Test
|
|
58
58
|
assert_equal('some-host', after.host)
|
59
59
|
assert_equal(9999, after.port)
|
60
60
|
end
|
61
|
+
|
62
|
+
def test_avoid_duplicate_processes
|
63
|
+
log = TestLogger.new(test_log)
|
64
|
+
time = Time.now
|
65
|
+
thread = Thread.start do
|
66
|
+
farmer = Zold::Farmers::Spawn.new(log: log)
|
67
|
+
farmer.up(Zold::Score.new(time: time, host: 'a', port: 1, invoice: 'prefixone@ffffffffffffffff', strength: 20))
|
68
|
+
end
|
69
|
+
assert_wait { !log.msgs.find { |m| m.include?('Scoring started') }.nil? }
|
70
|
+
assert_raises do
|
71
|
+
Zold::Farmers::Spawn.new(log: log).up(
|
72
|
+
Zold::Score.new(time: time, host: 'a', port: 1, invoice: 'prefixtwo@ffffffffffffffff', strength: 20)
|
73
|
+
)
|
74
|
+
end
|
75
|
+
thread.kill
|
76
|
+
thread.join
|
77
|
+
end
|
61
78
|
end
|