zold 0.16.11 → 0.16.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7821595a3b9487ea3138bbee7e70a4f6b960004d7e91a08147f5760a3bd6125c
4
- data.tar.gz: 37450f49b0f2d5e47ba9476ac83d14667eac4cf6b5b65fc10dd142fb8584b6ee
3
+ metadata.gz: b3c8beba4ea2ef38460a7107b2d1bf9d751f4dac69924ad31a8b87a771585349
4
+ data.tar.gz: a9cb982cbb48c63d6755f91251e95a8a72dc5a3dd68bf810001b8ded5994cdf8
5
5
  SHA512:
6
- metadata.gz: 3d09fdf2081fb1494a1e06b1b28ba8644b5cf4bf7197a6501811dd1f918ca5c7ac5979d1abc6f3b33fd80043922875a87ffe49f51a96c289ed27a2619aef8a6c
7
- data.tar.gz: 53b7bb8a8ded97904c9182f4bcc073b85d22b4b3b1cf1b878111a26c07d5c674880d8890e32bc398a1fb4262471b313d1f6b3ce9b644035d0f65a599b5641a3e
6
+ metadata.gz: b9d5e6df44283a6d75d49b75c5ecb5abb829059114699b4ddbd2e8629e1f76e306be5a64ce29c2f1fb2bf8f6508e7c21efa158325ee7186833d1689b8613d3c5
7
+ data.tar.gz: a6cc7024026e66a280af7e6410d9e10a1ea6bda8e7d1663e85630ad5077fa03b42991672cc69e3d7717f2e5244b56d571f56bcb2bd1c3b1e1da86f0161da137f
@@ -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
- @log.info("Terminating the farm with #{@threads.count} threads...")
162
- start = Time.now
163
- finish(@cleanup)
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 => _
@@ -55,8 +55,8 @@ module Zold
55
55
  'ruby',
56
56
  Shellwords.escape(bin),
57
57
  '--skip-upgrades',
58
- Shellwords.escape("--info-thread=#{Thread.current.name}"),
59
- Shellwords.escape("--info-start=#{Time.now.utc.iso8601}"),
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('TERM', pid)
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}")
@@ -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(:load, lifetime: 5 * 60) do
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
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.16.11'
28
+ VERSION = '0.16.12'
29
29
  PROTOCOL = 2
30
30
  end
@@ -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
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.11
4
+ version: 0.16.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko