lib/zold/node/farm.rb in zold-0.13.19 vs lib/zold/node/farm.rb in zold-0.13.20
- old
+ new
@@ -49,11 +49,11 @@
@semaphore = Mutex.new
end
def to_json
{
- threads: @threads.count,
+ threads: @threads.map { |t| "#{t.name}/#{t.status}" }.join(', '),
scores: @scores.size,
best: @best.count,
history: history.count
}
end
@@ -75,11 +75,11 @@
end
@threads << Thread.new do
VerboseThread.new(@log).run do
Thread.current.name = 'farm-cleaner'
loop do
- sleep(60)
+ sleep(60) unless strength == 1 # which will only happen in tests
clean(host, port, strength, threads)
end
end
end
@log.info("Farm started with #{@threads.count} threads at #{host}:#{port}, strength is #{strength}")
@@ -108,11 +108,12 @@
if @scores.length < threads || @best.count < threads
zero = Score.new(Time.now, host, port, @invoice, strength: strength)
@scores << zero
@best << zero
end
- @best = @best.reject(&:expired?).sort_by(&:value).reverse.take(threads)
+ @best = @best.reject(&:expired?).sort_by(&:value).reverse
+ @best = @best.take(threads) unless threads.zero?
end
def cycle(host, port, strength, threads)
clean(host, port, strength, threads)
s = @scores.pop
@@ -123,11 +124,11 @@
n = s.next
@semaphore.synchronize do
before = @best.map(&:value).max
save(n)
@best << n
- after = @best.map(&:value).max
clean(host, port, strength, threads)
+ after = @best.map(&:value).max
@log.debug("#{Thread.current.name}: best score is #{@best[0]}") if before != after && !after.zero?
end
@scores << n
end