Module: Carnivore::Utils::Failure

Included in:
Callback, Source, Source
Defined in:
lib/carnivore/utils/failure.rb

Overview

Failure utilities

Instance Method Summary collapse

Instance Method Details

#execute_and_retry_forever(action) ⇒ Object

Attempt to execute provided block. If exception is raised, log and pause before retry. Do this until success.

Parameters:

  • action (String, Symbol)

    display name for block

Returns:

  • (Object)

    result of yielded block



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/carnivore/utils/failure.rb', line 14

def execute_and_retry_forever(action)
  begin
    debug "Starting #{action} process"
    result = yield
    debug "Completed #{action} process"
    result
  rescue Zoidberg::DeadException
    raise
  rescue => e
    error "#{action.to_s.capitalize} process encountered an error: #{e.class} - #{e}"
    debug "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
    warn "Pausing for 5 seconds then retrying #{action}"
    sleep(5)
    retry
  end
end