Class Attempt
In: attempt.rb
Parent: Object

Methods

attempt   new  

Constants

VERSION = '0.1.1'

Attributes

increment  [RW]  If set, this increments the interval with each failed attempt by that number of seconds.
interval  [RW]  Number of seconds to wait between attempts. The default is 60.
level  [RW]  Determines which exception level to check when looking for errors to retry. The default is ‘Exception’ (i.e. all errors).
log  [RW]  If you provide an IO handle to this option then errors that would have been raised are sent to that handle.
timeout  [RW]  If set, the code block is further wrapped in a timeout block.
tries  [RW]  Number of attempts to make before failing. The default is 3.
warnings  [RW]  A boolean value that determines whether errors that would have been raised should be sent to STDERR as warnings. The default is true.

Public Class methods

Creates and returns a new Attempt object. Use a block to set the accessors.

Public Instance methods

Attempt to perform the operation in the provided block up to tries times, sleeping interval between each try. By default the number of tries defaults to 3, the interval defaults to 60 seconds, and there is no timeout specified.

If timeout is provided then the operation is wrapped in a Timeout block as well. This is handy for those rare occasions when an IO connection could hang indefinitely, for example.

If the operation still fails the (last) error is then re-raised.

This is really just a wrapper for Attempt.new where the simple case is good enough i.e. you don‘t care about warnings, increments or logging, and you want a little added convenience.

Example:

   # Make 3 attempts to connect to the database, 60 seconds apart.
   attempt{ DBI.connect(dsn, user, passwd) }

[Validate]