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

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
shishini
I think this twitter post and youtube video didn’t get as much attention as I hoped I am still new to Elixir, so can’t really judge ...
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
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
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

We're in Beta

About us Mission Statement