Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/asir/retry_behavior.rb | 51 | 38 | 45.10%
|
26.32%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 module ASIR |
2 # !SLIDE |
3 # Generic retry behavior |
4 module RetryBehavior |
5 # Maximum trys. |
6 attr_accessor :try_max |
7 # Initial amount of seconds to sleep between each try. |
8 attr_accessor :try_sleep |
9 # Amount of seconds to increment sleep between each try. |
10 attr_accessor :try_sleep_increment |
11 # Maxinum amount of seconds to sleep between each try. |
12 attr_accessor :try_sleep_max |
13 |
14 # Yields: |
15 # :try, n_try |
16 # :rescue, exc |
17 # :retry, exc |
18 # :failed, nil |
19 def with_retry |
20 n_try = 0 |
21 sleep_secs = try_sleep |
22 result = done = last_exception = nil |
23 begin |
24 n_try += 1 |
25 result = yield :try, n_try |
26 done = true |
27 rescue ::Exception => exc |
28 last_exception = exc |
29 yield :rescue, exc |
30 if ! try_max || try_max > n_try |
31 yield :retry, exc |
32 if sleep_secs |
33 sleep sleep_secs |
34 sleep_secs += try_sleep_increment if try_sleep_increment |
35 sleep_secs = try_sleep_max if try_sleep_max && sleep_secs > try_sleep_max |
36 end |
37 retry |
38 end |
39 end |
40 unless done |
41 unless yield :failed, last_exception |
42 exc = last_exception |
43 raise RetryError, "Retry failed: #{exc.inspect} \n#{exc.backtrace * "\n "}" |
44 end |
45 end |
46 result |
47 end |
48 class RetryError < Error; end |
49 end # module |
50 end # module ASIR |
51 |
Generated on Fri Jan 27 17:37:46 -0600 2012 with rcov 0.9.8