Exit loop after sometime

Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Reply

Join Date: Apr 2009
Posts: 1
Reputation: clai2x is an unknown quantity at this point 
Solved Threads: 0
clai2x clai2x is offline Offline
Newbie Poster

Exit loop after sometime

 
0
  #1
Apr 9th, 2009
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:

  1. def time_block
  2. start_time = Time.now
  3. Thread.new { yield }
  4. Time.now - start_time
  5. end
  6.  
  7. def repeat_every(seconds)
  8. begin
  9. time_spent = time_block { yield }
  10. sleep(seconds - time_spent)
  11. end while time_spent < seconds
  12. end
  13.  
  14. repeat_every(300) { # checking of email ever 5 minutes
  15. puts "Start checking: #{Time.now}"
  16. # email checking here
  17. puts "End checking: #{Time.now}"
  18. }
Last edited by peter_budo; Apr 9th, 2009 at 7:34 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC