HTTPoison Autoretry

I’ve been using this in my small app for a little bit and have noticed a decent reduction in the number of WTF errors w/ HTTPoison. In a production system HTTP requests are extremely failure prone and I’ve found that simply retrying the request after a small timeout fixes the problem. I’ve received everything from inabilities to resolve domain names (that clearly exist) to 500 errors from Amazon S3.

https://github.com/mgwidmann/httpoison_retry

Let me know if you like it.

I’m curious, why use a macro for this? Seems like a function would be fine.

2 Likes

So I thought about that a bit. The macro does end up wrapping it into a function internally, but the DSL wouldn’t flow very well if it required wrapping the input in a function. I’d imagine the code would look like this if it accepted a function instead…

fn -> HTTPoison.get("www.example.com") end
|> autoretry()
|> handle_response

I feel like that would lead to less readability and more confusion in general. How would you expect it to look using a function?

AH I see. I would 100% expect a literal function definition instead of a macro based one. That’s how Task, spawn, and a host of other functions like it work. What you have isn’t hideous but quite possibly you just do

request = fn ->
  HTTPoison.get("example.com")
end

request
|> auto_retry
|> handle_response

Did you consider using Retry in your package? Retry is quite configurable and has support for linear and exponential backoff strategies, among other things.

3 Likes

Oh awesome, didn’t know about that. Yeah, perhaps thats a better more generic library…

1 Like