zold 0.14.9 → 0.14.10

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
  SHA1:
3
- metadata.gz: 3f87074edd8e64584ac6834ed6646922c903c4f7
4
- data.tar.gz: 3e35c4e458186d16a9f5ebf2f635b7757525de74
3
+ metadata.gz: 2b7890a2a999ef13c0c3ca872f12005851a3ab16
4
+ data.tar.gz: d31b3c5551a454c18cc67d46dafc9c2264331d8c
5
5
  SHA512:
6
- metadata.gz: 05ff08a140bf66931a794d110ef12951389140836c2b0554ffb2e2abf738316d2c193a146decd7a71718e009e4ea9b839e5a7c6ac7778fffa8bab183788e17bc
7
- data.tar.gz: 5a30ccf3cdfccec6007140021160d197cb5e95728a83aeeb2bb8dc293e4f65d17be997b14396a6b86746e679f0d13d1e6787be56c3a3dd333209eb13ed8cd3d2
6
+ metadata.gz: 741c9ec83b2384608d9612a2fc4fa1593fe3a54141e1cf89fc89b66e15b4381adf8f29fa5829541afeda02c5807b8f2df58049a7267fe55fd50a453ec9836625
7
+ data.tar.gz: 48af3dd64a7904e03448c62f77464188cf6b3316a2f32683551a04236e5bcb5de5c5bee8587f7b92a612e27254c343b61f6c545dc84ae9ffa56e4d16aa41439d
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'concurrent'
23
24
  require 'csv'
24
25
  require 'uri'
25
26
  require 'time'
@@ -177,25 +178,31 @@ module Zold
177
178
  def iterate(log, farm: Farm::Empty.new)
178
179
  raise 'Log can\'t be nil' if log.nil?
179
180
  raise 'Farm can\'t be nil' if farm.nil?
181
+ return if all.empty?
180
182
  best = farm.best[0]
181
183
  require_relative 'score'
182
184
  score = best.nil? ? Score::ZERO : best
183
185
  idx = 0
186
+ pool = Concurrent::FixedThreadPool.new([all.count, Concurrent.processor_count * 16].min, max_queue: 0)
184
187
  all.each do |r|
185
- start = Time.now
186
- begin
187
- yield Remotes::Remote.new(r[:host], r[:port], score, idx, log: log, network: @network)
188
- idx += 1
189
- raise 'Took too long to execute' if (Time.now - start).round > Remotes::RUNTIME_LIMIT
190
- rescue StandardError => e
191
- error(r[:host], r[:port])
192
- errors = errors(r[:host], r[:port])
193
- log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message} \
194
- in #{(Time.now - start).round}s; errors=#{errors}")
195
- log.debug(Backtrace.new(e).to_s)
196
- remove(r[:host], r[:port]) if errors > Remotes::TOLERANCE
188
+ pool.post do
189
+ start = Time.now
190
+ begin
191
+ yield Remotes::Remote.new(r[:host], r[:port], score, idx, log: log, network: @network)
192
+ idx += 1
193
+ raise 'Took too long to execute' if (Time.now - start).round > Remotes::RUNTIME_LIMIT
194
+ rescue StandardError => e
195
+ error(r[:host], r[:port])
196
+ errors = errors(r[:host], r[:port])
197
+ log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message} \
198
+ in #{(Time.now - start).round}s; errors=#{errors}")
199
+ log.debug(Backtrace.new(e).to_s)
200
+ remove(r[:host], r[:port]) if errors > Remotes::TOLERANCE
201
+ end
197
202
  end
198
203
  end
204
+ pool.shutdown
205
+ raise 'Failed to terminate the pool' unless pool.wait_for_termination(60)
199
206
  end
200
207
 
201
208
  def errors(host, port = Remotes::PORT)
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.14.9'
29
- PROTOCOL = 1
28
+ VERSION = '0.14.10'
29
+ PROTOCOL = 2
30
30
  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.14.9
4
+ version: 0.14.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko