[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby thread question

Zach Buckholz

2/12/2007 5:32:00 PM

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

1 Answer

Chris Hulan

2/12/2007 5:36:00 PM

0

Get your own thread! 9^)

Message thread and Ruby thread...punny, yes? 8*)