[英]Remove extra characters from thread script
I've got a ruby script which check microservices version from each microservice API. 我有一个ruby脚本,该脚本检查每个微服务API的微服务版本。 I try to run this with bamboo and return the result as a html table. 我尝试用竹子运行它,并将结果作为html表返回。
...
h = {}
threads = []
service = data_hash.keys
service.each do |microservice|
threads << Thread.new do
thread_id = Thread.current.object_id.to_s(36)
begin
h[thread_id] = ""
port = data_hash["#{microservice}"]['port']
nodes = "knife search 'chef_environment:#{env} AND recipe:#
{microservice}' -i 2>&1 | tail -n 2"
node = %x[ #{nodes} ].split
node.each do |n|
h[thread_id] << "\n<html><body><h4> Node: #{n} </h4></body></html>\n"
uri = URI("http://#{n}:#{port}/service-version")
res = Net::HTTP.get_response(uri)
status = Net::HTTP.get(uri)
data_hash = JSON.parse(status)
name = data_hash['name']
version = data_hash['version']
h[thread_id] << "<table><tr><th> #{name}:#{version} </th></tr></table>"
end
rescue => e
h[thread_id] << "ReadTimeout Error"
next
end
end
end
threads.each do |thread|
thread.join
end
ThreadsWait.all_waits(*threads)
puts h.to_a
The issue is that I want to output name and version into a html table and if I put threads it generates some random characters between each line: 问题是我想将名称和版本输出到html表中,如果我放置线程,它将在每行之间生成一些随机字符:
<table><tr><th> microservice1:2.10.3 </th></tr></table>
bjfsw
<table><tr><th> microservice2:2.10.8 </th></tr></table>
The random characters are the keys of the hash generated with to_s(36)
. 随机字符是使用to_s(36)
生成的哈希的键。
Replace the puts h.to_a
with something like 将puts h.to_a
替换为类似
puts h.values.join("\n")
And you will only see the data and not the keys. 而且您只会看到数据,而不是键。
You can use kernel#ph
or puts h.inspect
to see this. 您可以使用kernel#ph
或puts h.inspect
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.