zold 0.13.21 → 0.13.22

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
  SHA1:
3
- metadata.gz: 9b54e147de6f13a87996515785862a09da82b1a5
4
- data.tar.gz: 332d33f707a6ad855001b9d77738d2f497622ef7
3
+ metadata.gz: e2e4d4e5e627137b421211b093b25dd2930423d7
4
+ data.tar.gz: e78835ebe8c5ead373287def6500d3d17a9ab648
5
5
  SHA512:
6
- metadata.gz: 6696d078025e97891007c9295fd2210de314c4dbbcef5e968fc4d7a9dd5b614c81903a4066ee4016074c7974321c1e3d656825f01d934ae0dcc55869aa693041
7
- data.tar.gz: 4463d7a107bbb6acb7a89931ae745dcc05598005cccaca4caf56c2484b5376f3ee07b595fca407376432bf4fcf7461408ff6f88aae52718165e784bf24faaff0
6
+ metadata.gz: e0d902fe84aa485c17b9785d83a832ca212c001db35bedd520026d1f4bc41e162006b3aecc3459192a9d5d24e6bfdbcd7a157edb871695b34fe663c816f35f6c
7
+ data.tar.gz: 176e92ee884fb86e0ef764bf05478cebb940183b07082f6f8ade8cec1162648cdcc319ace98fdd6776e9f2506afa9f2794163e483a0493445a252f97d9b619e2
@@ -155,7 +155,7 @@ module Zold
155
155
  invoice = Invoice.new(wallets: @wallets, log: @log).run(['invoice', invoice])
156
156
  end
157
157
  farm = Farm.new(invoice, File.join(Dir.pwd, 'farm'), log: @log)
158
- farm.start(opts[:host], opts[:port], threads: opts[:threads], strength: opts[:strength]) do
158
+ farm.start(host, opts[:port], threads: opts[:threads], strength: opts[:strength]) do
159
159
  Front.set(:farm, farm)
160
160
  metronome = metronome(farm, entrance, opts)
161
161
  begin
@@ -63,7 +63,7 @@ module Zold
63
63
  def to_json
64
64
  {
65
65
  threads: @threads.map do |t|
66
- "#{t.name}/#{t.status}/{t.alive? ? 'A' : 'D'}"
66
+ "#{t.name}/#{t.status}/#{t.alive? ? 'A' : 'D'}"
67
67
  end.join(', '),
68
68
  scores: @scores.size,
69
69
  best: @best.map(&:value).join(', '),
@@ -74,9 +74,8 @@ module Zold
74
74
  def start(host, port, strength: 8, threads: 8)
75
75
  @log.debug('Zero-threads farm won\'t score anything!') if threads.zero?
76
76
  @scores = Queue.new
77
- h = history(threads)
78
- h.each { |s| @scores << s }
79
- @best << (h[0] || Score.new(Time.now, host, port, @invoice, strength: strength))
77
+ @best = history
78
+ clean(host, port, strength, threads)
80
79
  @log.info("#{@scores.size} scores pre-loaded, the best is: #{@best[0]}")
81
80
  @threads = (1..threads).map do |t|
82
81
  Thread.new do
@@ -121,21 +120,19 @@ module Zold
121
120
 
122
121
  def clean(host, port, strength, threads)
123
122
  @mutex.synchronize do
124
- before = @best.map(&:value).max
125
- @best = @best.reject(&:expired?).sort_by(&:value).reverse
123
+ before = @best.map(&:value).max.to_i
124
+ @best = @best.select(&:valid?).reject(&:expired?).sort_by(&:value).reverse
126
125
  @best = @best.take(threads) unless threads.zero?
127
- if @scores.length < threads || @best.count < threads
128
- zero = Score.new(Time.now, host, port, @invoice, strength: strength)
129
- @scores << zero
130
- @best << zero
126
+ if @best.empty? || !threads.zero? && @best.map(&:age_hours).min > 24 / threads
127
+ @best << Score.new(Time.now, host, port, @invoice, strength: strength)
131
128
  end
129
+ @best.sort_by(&:age_hours).each { |b| @scores << b }
132
130
  after = @best.map(&:value).max
133
131
  @log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
134
132
  end
135
133
  end
136
134
 
137
135
  def cycle(host, port, strength, threads)
138
- clean(host, port, strength, threads)
139
136
  s = @scores.pop
140
137
  return unless s.valid?
141
138
  return unless s.host == host
@@ -154,7 +151,7 @@ module Zold
154
151
  AtomicFile.new(@cache).write((history + [score]).map(&:to_s).uniq.join("\n"))
155
152
  end
156
153
 
157
- def history(max = 16)
154
+ def history
158
155
  if File.exist?(@cache)
159
156
  AtomicFile.new(@cache).read
160
157
  .split(/\n/)
@@ -162,7 +159,6 @@ module Zold
162
159
  .select(&:valid?)
163
160
  .sort_by(&:value)
164
161
  .reverse
165
- .take(max)
166
162
  else
167
163
  []
168
164
  end
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.13.21'.freeze
26
+ VERSION = '0.13.22'.freeze
27
27
  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.13.21
4
+ version: 0.13.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko