Class: Masamune::Commands::RetryWithBackoff
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Masamune::Commands::RetryWithBackoff
- Defined in:
- lib/masamune/commands/retry_with_backoff.rb
Constant Summary collapse
- MAX_RETRY_EXIT_STATUS =
8
Instance Method Summary collapse
- #around_execute(&block) ⇒ Object
-
#initialize(delegate, attrs = {}) ⇒ RetryWithBackoff
constructor
A new instance of RetryWithBackoff.
Constructor Details
#initialize(delegate, attrs = {}) ⇒ RetryWithBackoff
Returns a new instance of RetryWithBackoff.
29 30 31 32 33 34 35 |
# File 'lib/masamune/commands/retry_with_backoff.rb', line 29 def initialize(delegate, attrs = {}) super delegate @delegate = delegate @max_retries = attrs.fetch(:max_retries, configuration.max_retries) @backoff = attrs.fetch(:backoff, configuration.backoff) @retry_count = 0 end |
Instance Method Details
#around_execute(&block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/masamune/commands/retry_with_backoff.rb', line 37 def around_execute(&block) status = if @delegate.respond_to?(:around_execute) @delegate.around_execute(&block) else yield end raise "exited with code: #{status.exitstatus}" unless status.success? status rescue => e logger.error(e.to_s) sleep @backoff @retry_count += 1 if @retry_count > @max_retries logger.debug("max retries (#{@max_retries}) attempted, bailing") OpenStruct.new(success?: false, exitstatus: MAX_RETRY_EXIT_STATUS) else logger.debug("retrying (#{@retry_count}/#{@max_retries})") retry end end |