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

scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New

We're in Beta

About us Mission Statement