Module: HTTPX::Plugins::Retries::OptionsMethods

Defined in:
lib/httpx/plugins/retries.rb

Overview

adds support for the following options:

:max_retries

max number of times a request will be retried (defaults to 3).

:retry_change_requests

whether idempotent requests are retried (defaults to false).

:retry_after

seconds after which a request is retried; can also be a callable object (i.e. ->(req, res) { ... } )

:retry_jitter

number of seconds applied to :retry_after (must be a callable, i.e. ->(retry_after) { ... } ).

:retry_on

callable which alternatively defines a different rule for when a response is to be retried (i.e. ->(res) { ... }).

Instance Method Summary collapse

Instance Method Details

#option_max_retries(value) ⇒ Object

Raises:

  • (TypeError)


77
78
79
80
81
82
# File 'lib/httpx/plugins/retries.rb', line 77

def option_max_retries(value)
  num = Integer(value)
  raise TypeError, ":max_retries must be positive" unless num >= 0

  num
end

#option_retry_after(value) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/httpx/plugins/retries.rb', line 60

def option_retry_after(value)
  # return early if callable
  unless value.respond_to?(:call)
    value = Float(value)
    raise TypeError, ":retry_after must be positive" unless value.positive?
  end

  value
end

#option_retry_change_requests(v) ⇒ Object



84
85
86
# File 'lib/httpx/plugins/retries.rb', line 84

def option_retry_change_requests(v)
  v
end

#option_retry_jitter(value) ⇒ Object

Raises:

  • (TypeError)


70
71
72
73
74
75
# File 'lib/httpx/plugins/retries.rb', line 70

def option_retry_jitter(value)
  # return early if callable
  raise TypeError, ":retry_jitter must be callable" unless value.respond_to?(:call)

  value
end

#option_retry_on(value) ⇒ Object

Raises:

  • (TypeError)


88
89
90
91
92
# File 'lib/httpx/plugins/retries.rb', line 88

def option_retry_on(value)
  raise TypeError, ":retry_on must be called with the response" unless value.respond_to?(:call)

  value
end