Fl4m3Ph03n1x
Background
We have an app that deals with a considerable amount of requests per second. This app needs to notify an external service, by making a GET call via HTTPS to one of our servers.
Objective
The objective here is to use HTTPoison to make async GET requests. I don’t really care about the response of the requests, all I care is to know if they failed or not, so I can write any possible errors into a logger.
If it succeeds I don’t want to do anything.
Research
I have checked the official documentation for HTTPoison and I see that they support async requests:
However, I have 2 issues with this approach:
- They use
flushto show the request was completed. I can’t loggin into the app and manuallyflushto see how the requests are going, that would be insane. - They don’t show any notifications mechanism for when we get the responses or errors.
So, I have a simple question:
- How do I get asynchronously notified that my request failed or succeeded?
I assume that the default HTTPoison.get is synchronous, as shown in the documentation.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
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
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
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
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
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
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #elixirconf-us
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
outlog
I would use Task.start - and then log the error from there should it fail..
Fl4m3Ph03n1x
Interesting idea, but I am a little bit interested in the result, i.e., as I explained I would like to know if the request failed so I can log it.
Furthermore using Task means I wouldn’t be able to take advantage of the hackney pools HTTPoison uses, so I would have to create a Task (process) for each request instead of taking advantage of the pools already in place, which would result in far less efficient alternative.
sanswork
Spawn a new process with a receive block and point your stream_to at that instead of self.
NobbZ
use
receiveto receive the messages… remember to drop those you don’t want to see…Fl4m3Ph03n1x
@sanswork
@NobbZ
So there is no way to do this asynchronously using HTTPoison?
What is the
asyncdocumentation for then? How would one even use it?I swear I am getting more confused as time goes by.
sanswork
What we just described is asyc using httpoison.
NobbZ
Of course it is.
receivethe payloadThats async for me.
If you do not want to do this in the process that deals with the other stuff, you have to offload it into another process.
lpil
Unlike in most languages in Elixir or Erlang it’s trivial for a function to be made asynchronous using processes (possibly using an abstraction such as Task). Because of this we don’t need libraries to implement async versions of the functions they offer- and often we would prefer them not to as one size does not fit all here.
outlog
eg you can easily log any errors. (obviously use start/3 for “real” DRY code..)
You can use the pools..
But not sure I understand all the requirements..
Fl4m3Ph03n1x
The reason I mention why this is confusing is because
receiveis actually blocking. According to the documentation:I don’t want my process to wait for anything. I want it to go around doing it’s business and if it receives something, to act accordingly. I don’t want to block a process waiting for a response. In reality this would be a perfect case of fire and forget but since I need to know if something failed it is not 100% fire and forget.
So I hope you understand my confusion when you people tell me to use
receive, which according to my understanding, actually blocks the process until it receives something.I guess under this assumption Task.start would make more sense, since I could block the Task instead.
Not sure I agree with the philosophy, but the insight is surely appreciated! It helps me put into context the responses I have been getting thus far!