Req.retry

You're seeing just the function retry, go back to Req module for more information.
Link to this function

retry(request, response_or_exception, options \\ [])

View Source

Retries a request in face of errors.

This function can be used as either or both response and error step. It retries a request that resulted in:

  • a response with status 5xx

  • an exception

Options

  • :delay - sleep this number of milliseconds before making another attempt, defaults to 2000

  • :max_attempts - maximum number of retry attempts, defaults to 2 (for a total of 3 requests to the server, including the initial one.)

Examples

With default options:

iex> Req.get!("https://httpbin.org/status/500,200", retry: true).status
# 19:02:08.463 [error] Req.retry/3: Got response with status 500. Will retry in 2000ms, 2 attempts left
# 19:02:10.710 [error] Req.retry/3: Got response with status 500. Will retry in 2000ms, 1 attempt left
200

With custom options:

iex> Req.get!("http://localhost:9999", retry: [delay: 100, max_attempts: 3])
# 17:00:38.371 [error] Req.retry/3: Got exception. Will retry in 100ms, 3 attempts left
# 17:00:38.371 [error] ** (Mint.TransportError) connection refused
# 17:00:38.473 [error] Req.retry/3: Got exception. Will retry in 100ms, 2 attempts left
# 17:00:38.473 [error] ** (Mint.TransportError) connection refused
# 17:00:38.575 [error] Req.retry/3: Got exception. Will retry in 100ms, 1 attempt left
# 17:00:38.575 [error] ** (Mint.TransportError) connection refused
** (Mint.TransportError) connection refused