TrebleMan
Superstar
What did you use to make the requests? GenServer, Tasks, Agents, or just spawned processes?
I actually used the httpoison library for it:
GitHub - edgurgel/httpoison: Yet Another HTTP client for Elixir powered by hackney
Another link, applying it:
Snip2Code - Async vs Sync http requests
If I remember correctly, I did something that looks like what they had in the code:
Code:
urls = ["https://someapi with post info", "https://someapi with post info2", ...]
...
urls
|> Enum.map(fn(url) -> Task.async(fn -> HTTPoison.post(url, body, headers, timeout: 1500) end) end)
|> Enum.map(&Task.await(&1, 30000))
|> Enum.each(fn({status, result}) ->
if (status == :ok) do
# uploaded result to db
else
# sent error message
end
end)
Code:
body = Poison.encode!(%{
"api_key": api_key,
"user_id": user.id
})
headers = [{"Content-type","application/json"}]
Last edited: