lib/zold/node/farm.rb in zold-0.13.26 vs lib/zold/node/farm.rb in zold-0.13.27
- old
+ new
@@ -113,17 +113,13 @@
private
def cleanup(host, port, strength, threads)
scores = load
before = scores.map(&:value).max.to_i
- if scores.empty? || !threads.zero? && scores.map(&:age).min > 24 * 60 * 60 / threads
- save([Score.new(Time.now, host, port, @invoice, strength: strength)])
- else
- save
- end
+ save(threads, [Score.new(Time.now, host, port, @invoice, strength: strength)])
scores = load
- @pipeline << scores.min_by(&:age) if @pipeline.size.zero?
+ @pipeline << scores.max_by(&:age) if @pipeline.size.zero?
after = scores.map(&:value).max.to_i
@log.debug("#{Thread.current.name}: best score is #{scores[0]}") if before != after && !after.zero?
end
def cycle(host, port, strength, threads)
@@ -131,22 +127,24 @@
return unless s.valid?
return unless s.host == host
return unless s.port == port
return unless s.strength >= strength
Thread.current.name = s.to_mnemo
- save([s.next])
+ save(threads, [s.next])
cleanup(host, port, strength, threads)
end
- def save(list = [])
+ def save(threads, list = [])
scores = load + list
+ period = 24 * 60 * 60 / [threads, 1].max
@mutex.synchronize do
AtomicFile.new(@cache).write(
scores.select(&:valid?)
.reject(&:expired?)
.sort_by(&:value)
.reverse
.uniq(&:time)
+ .uniq { |s| s.age % period }
.map(&:to_s)
.uniq
.join("\n")
)
end