CharlesO

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

axelson

Scenic Core Team

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

hilko

Could it work to just spawn a task that just times out after that amount of time?

CharlesO

CharlesO

I added retry: false as well, so far the receive_timeout: 2000 seems okay

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement