module HTTPX::Plugins::Retries

  1. lib/httpx/plugins/retries.rb

This plugin adds support for retrying requests when certain errors happen.

gitlab.com/honeyryderchuck/httpx/wikis/Retries

Methods

Public Class

  1. extra_options

Constants

IDEMPOTENT_METHODS = %i[get options head put delete].freeze  

TODO: pass max_retries in a configure/load block

MAX_RETRIES = 3  
RETRYABLE_ERRORS = [IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, (OpenSSL::SSL::SSLError if defined?(OpenSSL)), TimeoutError, Parser::Error, Errno::EINVAL, Errno::ETIMEDOUT].freeze  

Public Class methods

extra_options (options)
[show source]
   # File lib/httpx/plugins/retries.rb
26 def self.extra_options(options)
27   Class.new(options.class) do
28     # number of seconds after which one can retry the request
29     def_option(:retry_after) do |num|
30       # return early if callable
31       unless num.respond_to?(:call)
32         num = Integer(num)
33         raise Error, ":retry_after must be positive" unless num.positive?
34       end
35 
36       num
37     end
38 
39     def_option(:max_retries) do |num|
40       num = Integer(num)
41       raise Error, ":max_retries must be positive" unless num.positive?
42 
43       num
44     end
45 
46     def_option(:retry_change_requests)
47 
48     def_option(:retry_on) do |callback|
49       raise ":retry_on must be called with the response" unless callback.respond_to?(:call)
50 
51       callback
52     end
53   end.new(options).merge(max_retries: MAX_RETRIES)
54 end