Ruby thread question

Z

Zach Buckholz

I have a script that goes thru each server in the environment and
updates a database with the current rpm package info. It's used for
tracking, to make sure all servers have the same versions etc. and query
when something has changed.

It's been successful for about 1 year now, but as the environment has
grown it takes longer to complete so I am trying to use ruby threads to
fire off multiple server checks at the same time.

I added what I believe is the correct logic below, but this does not
seem to work. All servers get their own thread, and start running. But
as soon as one completes the entire script exists as if it has completed
successfully.

Any insight would be appreciated.

Thanks
Zach


#!/usr/local/bin/ruby
require 'thread'
require "servers"
require 'net/ssh'
require 'rpmlist'
require 'rpmmysql'
require 'rpm'

class RPMAudit
serversObj =3D Servers.new()
threads =3D []
serversObj.all.each { |x|
threads << Thread.new(x) { |y|
hostName =3D y[1] + "." + y[2]
print "HOSTNAME : ", hostName, "
started:\n"
result =3D RPMList.new(hostName)
if(result.rpmArray =3D=3D nil) then
next
end
rpmThreads =3D []
result.rpmArray.each { |y|
rpmThreads << Thread.new(y) {
|z|
package =3D RPM.new( z )
if(package.signature =
=3D=3D
nil) then next end
print "."
STDOUT.flush
sql =3D
RPMMysql.new(package,hostName)
}
rpmThreads.each { |bthread|
bthread.join }
}
print "HOSTNAME : ", hostName, "
ended:\n"
}
}
threads.each { |aThread| aThread.join }
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top