Class: SSLErrorMgt

Inherits:
Object
  • Object
show all
Defined in:
lib/process/cloud/process/common.rb

Overview

Class to manage retry on errors before failing

Instance Method Summary collapse

Constructor Details

#initialize(iMaxRetry = 5) ⇒ SSLErrorMgt

Returns a new instance of SSLErrorMgt.



28
29
30
31
# File 'lib/process/cloud/process/common.rb', line 28

def initialize(iMaxRetry = 5)
  @retry = 0
  @max_retry = iMaxRetry
end

Instance Method Details

#error_detected(message, backtrace, e) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/process/cloud/process/common.rb', line 49

def error_detected(message, backtrace, e)
  if message.match('SSLv2/v3 read server hello A: unknown protocol')
    return wait(message, "'unknown protocol' SSL Error")
  elsif e.is_a?(Excon::Errors::InternalServerError)
    return wait(message, ANSI.red(e.class))
  else
    PrcLib.error("Exception %s: %s\n%s", e.class, message,
                 backtrace.join("\n"))
    return true
  end
end

#wait(message, issue = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/process/cloud/process/common.rb', line 33

def wait(message, issue = nil)
  if @retry < @max_retry
    sleep(2)
    @retry += 1
    if PrcLib.level == 0
      msg = format('%s/%s try... ', @retry, @max_retry)
      msg += issue unless issue.nil?
      print msg
    end
    return false
  else
    PrcLib.error('Too many retry. %s', message)
    return true
  end
end