httpoison_retry v1.1.0 HTTPoison.Retry View Source

See Elixir.HTTPoison.Retry.autoretry/2

Link to this section Summary

Functions

Takes in a HTTP fetch command and will attempt and reattempt it over and over up to a maximum amount without any intervention on behalf of the user.

Link to this section Functions

Link to this macro

autoretry(attempt, opts \\ []) View Source (macro)

Takes in a HTTP fetch command and will attempt and reattempt it over and over up to a maximum amount without any intervention on behalf of the user.

Example:

HTTPoison.get("https://www.example.com")
# Will retry 5 times waiting 15.0s between each before returning
# Note: below is the same as the defaults
|> autoretry(max_attempts: 5, wait: 15000, include_404s: false, retry_unknown_errors: false)
# Your function which will handle the response after success or the 5 failed retries
|> handle_response()

Gotcha

Don't forget that the autoretry/2 call could take a substaintial amount of time to complete. That means usage in the following areas are potential problems:

  • Within a plug/phoenix request
  • Within any GenServer process

    • Sleeping for a considerable amount of time leaves the process unable to answer other callers and will result in cascading timeouts of other processes
  • Any Task/Agent call that has a timeout period (i.e. Task.await/1)

  • Tests

    • Tests should not be making live HTTP calls anyhow, but if they do this could potentially go over the default 60 seconds in ExUnit.
Link to this function

next_attempt(attempt, opts) View Source