lib/zold/node/farm.rb in zold-0.16.4 vs lib/zold/node/farm.rb in zold-0.16.5
- old
+ new
@@ -22,10 +22,11 @@
require 'time'
require 'open3'
require 'backtrace'
require 'futex'
+require 'json'
require_relative '../log'
require_relative '../score'
require_relative '../age'
require_relative '../verbose_thread'
require_relative 'farmers'
@@ -57,20 +58,28 @@
def best
load
end
def to_text
- @threads.map do |t|
- trace = t.backtrace || []
- "#{t.name}: status=#{t.status}; alive=#{t.alive?};\n #{trace.join("\n ")}"
- end.join("\n")
+ [
+ "Current time: #{Time.now.utc.iso8601}",
+ JSON.pretty_generate(to_json),
+ @threads.map do |t|
+ trace = t.backtrace || []
+ [
+ "#{t.name}: status=#{t.status}; alive=#{t.alive?}",
+ 'Vars: ' + t.thread_variables.map { |v| "#{v}=\"#{t.thread_variable_get(v)}\"" }.join('; '),
+ " #{trace.join("\n ")}"
+ ].join("\n")
+ end
+ ].flatten.join("\n\n")
end
def to_json
{
threads: @threads.map do |t|
- "#{t.name}/#{t.status}/#{t.alive? ? 'A' : 'D'}"
+ "#{t.name}/#{t.status}/#{t.alive? ? 'alive' : 'dead'}"
end.join(', '),
cleanup: @cleanup.status,
pipeline: @pipeline.size,
best: best.map(&:to_mnemo).join(', '),
alive: @alive
@@ -175,9 +184,10 @@
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
+ Thread.current.thread_variable_set(:start, Time.now.utc.iso8601)
score = @farmer.up(s)
@log.debug("New score discovered: #{score}")
save(threads, [score])
cleanup(host, port, strength, threads)
end