{:ok, tas} = Task.Supervisor.start_link(restart: :transient, max_restarts: 4)
a = 1
Task.Supervisor.async_nolink(tas, fn -> IO.puts "#{a}..." end)
Task.Supervisor.async_nolink(tas, fn ->
IO.puts "Not Restarting :( "
1 = 2
end)
a = a + 1
Task.Supervisor.async_nolink(tas, fn -> IO.puts "#{a}.." end)
a = a + 1
Task.Supervisor.async_nolink(tas, fn -> IO.puts "#{a}.." end)
The option restart: :transientdoes not seem to have any effect.
I have few tasks Task.async(fn(x) -> fetch_info(x) endthat make an HTTP request to get multiple resources and have a timeout error. It would be nice to repeat the failed task instead of using try, rescue.
I think that async_nolinkis the closest I got without a process crash. If there is no way to use Task, we have a simpler approach, using Supervisor, which starts several processes that exist after they are executed and restart them if they do not work?
source
share