josefrichter

josefrichter

Async POST to external API?

Hi. I need to make a POST to external API every 10s or so. I don’t necessarily we’d to wait for the response. But in case the response is not 200, I might want to do something, show error or raise exception. The request may take a few seconds sometimes, so a few requests may end up running concurrently.

What is the proper simple way, please?

I ended up with some this like Task.Supervisor.start_child but is that the proper way?

Thank you very much.

Most Liked

quatermain

quatermain

hi, yes, why not. You can create GenServer which will run Process.send_after/4 after he execute Task.start/1. You can have own TaskSupervisor who can manage running processes. But I think you can have some issues in future, but it depends on external API. I like idea of Mint. There is a pool of connections to every domain. So you can have one pool for your external API. You can use Finch or Tesla middleware for Finch.

You should think about and handle errors because you should take care of your task process so this new process will never crash. It can crash but it can be messy in logs when you have about 9000 requests per day. And in case external api is down for 10 minutes you don’t want to see 1_000 lines of errors. It depends what to you want to do when your process crash or you can handle it with just Logger.error…

I like Tesla because you can add Retry middleware where you can setup retry when you get network error. These errors happen because of ISP, clouds, etc… But it depends what do you want to achieve with this calls.

josefrichter

josefrichter

thank you!

Where Next?

Popular in Discussions Top

chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19568 166
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
jsonify
So, is Heroku the only free option for hosting Phoenix/Elixir at this point? I’m not ready to commit to paying monthly and was wondering ...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
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

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement