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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5c735ab0c917e4b346f598206c82a224a81caf5e6e3629d73203cb918bd6200
4
- data.tar.gz: 41f2241f736aab555d0fd2a32481814c2142121339488a7e6269506a398204d2
3
+ metadata.gz: fecaea03a1281af059406fd284d9b814fac0e4d0646ef6e65d8b4aacbf813169
4
+ data.tar.gz: 5e9a58d162b1333189e6346a25e2d24c411ec4bf3a3f074ab2c0a3d3e1185a57
5
5
  SHA512:
6
- metadata.gz: 8b477ea12a0c08aff12a68c5f07af44e13ebd131c0c156b9cde6fcf62da81fe21ffab32c3dc13483ec330a0f8a01ad8efcb67bc8612b772ea812bff5fe5b2a8a
7
- data.tar.gz: 2eed2bff0ee50b4136088e2ad3a8b7c1ca80cffe02115f25891eeb6d45129bc590387134afbe22ed3bce1bf8c944c507aff07aa4708d5e7395b5b90998c2d045
6
+ metadata.gz: 9a71a411222753fc52f30ae2e4c9f7e374832840430cedfde87f5572ee7f1a67f41365bc17ac8fb708feaeb77ac8ad9e4c8c7137f61568d0734ba845f1561a47
7
+ data.tar.gz: aad4fc840d9e5c87315f6a4d1c4997e326511eb94910c1aec9496b89e37ea7c7926b0ae55d69f31bc069d374a946eebf12c395060b168a992d2f9c03ddb5a809
@@ -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
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.16.19'
28
+ VERSION = '0.16.20'
29
29
  PROTOCOL = 2
30
30
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.19
4
+ version: 0.16.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko