DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Ruby (http://www.daniweb.com/forums/forum73.html)
-   -   Exit loop after sometime (http://www.daniweb.com/forums/thread185894.html)

clai2x Apr 9th, 2009 3:05 am
Exit loop after sometime
 
please excuse me, i'm not a developer but a tester and i'm no good at doing programming stuff and all. im into automation now for my testing and i choose to use ruby for it but i have a problem hope you guys could help me out of this...

i need to do a script that will check my email every 5minutes and after 20minutes of no new mail it will produce "test fail". i have found a cool code for checking email every 5min but i could not find a way to stop it after 20minutes? any help is greatly appreciated :)

here's the code:

def time_block
  start_time = Time.now
  Thread.new { yield }
  Time.now - start_time
end

def repeat_every(seconds)
 begin
    time_spent = time_block { yield }
    sleep(seconds - time_spent)
 end while time_spent < seconds
end

repeat_every(300) { # checking of email ever 5 minutes
  puts "Start checking: #{Time.now}"
  # email checking here
  puts "End checking: #{Time.now}"
}


All times are GMT -4. The time now is 3:10 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC