CharlesO
Limit request total timeout to just 2000ms with Req
How do we limit a Req.post! or Req.get! to a total timeout of just 2000ms?
I have an integration that needs very timely responses.
Limiting external API requests to just 2000ms would help my integration scenario.
I have looked at the documentation, but I’m not getting it at all.
As usual, AI suggestions are no use either.
suggested code - Via WhatsApp Meta AI Llama 3.2
def test do
Req.get!("https://api.github.com/repos/wojtekmach/req",
finch: [
options: [
timeout: 2000,
receive_timeout: 2000
]
]
)
end
Marked As Solved
axelson
I think the Finch option you want is :request_timeout:
The amount of time to wait for a complete response before returning an error. This timeout only applies to HTTP/1, and its current implementation is a best effort timeout, it does not guarantee the call will return precisely when the time has elapsed. Default value is
:infinity.
And if you’re using HTTP/2 then that won’t work.
And the syntax to set the various timeouts looks like:
Req.get("https://httpbin.org", connect_options: [timeout: 500], receive_timeout: 2000, pool_timeout: 500)
The main place to see those options is at: Req — req v0.6.2
But I’m pretty sure those various timeouts all stack so if you want to limit the total time I agree with @hilko that a Task is your best bet.
Also Liked
hilko
Could it work to just spawn a task that just times out after that amount of time?
CharlesO
I added retry: false as well, so far the receive_timeout: 2000 seems okay
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








