943,548 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Unsolved
  • Views: 2423
  • Ruby RSS
Apr 9th, 2009
0

Exit loop after sometime

Expand Post »
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:

ruby Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
clai2x is offline Offline
1 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: Ruby - GUI - Desktop Programming - Tools required
Next Thread in Ruby Forum Timeline: Configure SciTE - accept keyboard inut





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC