CharlesO

CharlesO

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

Showing Posts 1 to 5

CharlesO

CharlesO OP

this seems to limit just the connection part, but not the entire request duration

Req.get!("https://httpbin.org", connect_options: [timeout: 2000])

hilko

hilko

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

CharlesO

CharlesO OP

If I Cannot get the Req to behave as I expect it to, then your idea is indeed solid.

Thanks.

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.

CharlesO

CharlesO OP

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

CodeSync
Practical Data Orchestration in Elixir - Silvia Zeamer | ElixirConf EU 2026 https://www.youtube.com/watch?v=bVb1xmf3S34 Comments welco...
New
preciz
I like to find performance optimizations and hidden bugs in Elixir codebases with coding agents. If I just ask them directly to find tho...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews