Module: Magellan::Cli::Ssl

Defined in:
lib/magellan/cli/ssl.rb

Constant Summary collapse

DEFAULT_MAX_RETRY_COUNT =
(ENV["MAGELLAN_CLI_MAX_RETRY_COUNT"] || 10).to_i

Class Method Summary collapse

Class Method Details

.retry_on_ssl_error(name, options = {}) ⇒ Object

SSLエラー発生時に規定の回数までリトライします

Parameters:

  • name (String)

    エラー発生時に標準エラー出力に出力する文字列。処理の名前を想定しています。

  • options (Hash) (defaults to: {})

    オプション

Options Hash (options):

  • :max_retry_count (Integer)

    最大リトライ回数。指定がない場合は MAGELLAN_CLI_MAX_RETRY_COUNT から、それも無ければ固定値10が使用されます。

  • :interval (Numeric)

    リトライ時のインターバルの秒数。デフォルトは0.2秒。



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/magellan/cli/ssl.rb', line 17

def retry_on_ssl_error(name, options = {})
  max_retry_count = (options[:max_retry_count] || DEFAULT_MAX_RETRY_COUNT).to_i
  interval = options[:interval] || 0.2
  retry_count = 0
  begin
    return yield
  rescue OpenSSL::SSL::SSLError => e
    $stderr.puts("retrying #{name} [#{e.class.name}] #{e.message}")
    sleep(interval)
    retry_count += 1
    retry if retry_count <= max_retry_count
    raise e
  end
end