I’m using Ruby threads like this:
threads = []
for page in pages
threads << Thread.new(page) { |myPage|
h = Net::HTTP.new(myPage, 80)
puts "Fetching: #{myPage}"
resp, data = h.get('/', nil )
puts "Got #{myPage}: #{resp.message}"
}
end
threads.each { |aThread| aThread.join }
Let’s say I wanted to kill all threads that are still running after a minute. How would I do this?
I usually timeout my operations with Timeout:
Maybe this can help, so in your case, I think something like this should work:
But are you sure your controller is the best place to be doing this? Wouldn’t they be better off in a background task?