Class: Rescue::Handler
- Inherits:
-
Object
- Object
- Rescue::Handler
- Defined in:
- lib/rescue/handler.rb
Instance Attribute Summary collapse
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Handler
constructor
A new instance of Handler.
Constructor Details
#initialize(options = {}) ⇒ Handler
Returns a new instance of Handler.
7 8 9 10 11 12 13 |
# File 'lib/rescue/handler.rb', line 7 def initialize( = {}) @errors = [:errors] || [] @max_attempts = [:max_attempts] || 3 @delay = [:delay] || :none @logger = [:logger] || ::Logger.new($stdout) @attempt = 1 end |
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
5 6 7 |
# File 'lib/rescue/handler.rb', line 5 def attempt @attempt end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
5 6 7 |
# File 'lib/rescue/handler.rb', line 5 def delay @delay end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/rescue/handler.rb', line 5 def errors @errors end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/rescue/handler.rb', line 5 def logger @logger end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
5 6 7 |
# File 'lib/rescue/handler.rb', line 5 def max_attempts @max_attempts end |
Instance Method Details
#call(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/rescue/handler.rb', line 15 def call(&block) block.call rescue *errors => e log_attempt(e) raise if max_attempts? @attempt += 1 sleep delay_retry(attempt) unless delay == :none retry end |