public
Fork of jschementi/ironruby-stats
Description: Statistics for IronRuby
Homepage: http://ironruby.info
Clone URL: git://github.com/jredville/ironruby-stats.git
ironruby-stats / retry.rb
100644 47 lines (39 sloc) 1.097 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'win32ole'
require 'rubygems'
require 'win32/process'
require 'dbg'
 
puts "Cleaning ..."
system 'ruby stats.rb --clean'
 
$duration = 45 * 60
$retry_count = 0
$retry_times = 2
 
while $retry_count <= $retry_times
  retryer = Thread.new do
    puts "Waiting #{$duration} seconds for you to run"
    sleep($duration)
    puts "\n... ready or not, hear I come!"
 
    found = false
 
    wmi = WIN32OLE.connect("winmgmts://")
    wmi.ExecQuery("select * from win32_process").each do |process|
      if process.CommandLine == 'ruby stats.rb --all'
        fount = true
        puts "Found you hanging, so stop running!"
        $retry_count += 1
        `taskkill /PID #{process.ProcessId} /F`
        `taskkill /PID ir.exe /F`
        if $retry_count <= $retry_times
          puts "Running you again"
        else
          puts "You've hung too many times, you're done."
        end
        Thread.exit
      end
    end
 
    unless found
      puts "Never found ruby.exe, so stop retrying!"
      Thread.exit
    end
  end
 
  Thread.new{ system 'ruby stats.rb --all' }.join
  retryer.join
end