lib/zold/node/farm.rb in zold-0.10.19 vs lib/zold/node/farm.rb in zold-0.10.20
- old
+ new
@@ -59,10 +59,11 @@
def start(host, port, strength: 8, threads: 8)
@log.debug('Zero-threads farm won\'t score anything!') if threads.zero?
@best << Score.new(Time.now, host, port, @invoice, strength: strength)
@scores = Queue.new
history.each { |s| @scores << s }
+ @log.debug("#{@scores.size} scores pre-loaded") unless @scores.size.zero?
@threads = (1..threads).map do |t|
Thread.new do
VerboseThread.new(@log).run do
Thread.current.name = "farm-#{t}"
loop do
@@ -101,15 +102,15 @@
end
private
def save(score)
- File.write(@cache, (history.reject(&:expired?) + [score]).map(&:to_s).join("\n"))
+ File.write(@cache, (history + [score]).map(&:to_s).join("\n"))
end
def history
if File.exist?(@cache)
- File.readlines(@cache).map { |t| Score.parse(t) }
+ File.readlines(@cache).map { |t| Score.parse(t) }.reject(&:expired?)
else
[]
end
end
end