I’ve a Task which is started under supervision, within this Task, I spawn a few additional Tasks, I was wondering how supervision will be for the additional Tasks spawned within the Task under supervision.
def validate_sim_phone_status(msisdn) do
task1 = Task.async(fn -> is_4G_phone(msisdn) end)
task2 = Task.async(fn -> is_4G_sim?(msisdn) end)
task3 = Task.async(fn -> is_4G_phone_alt?(msisdn) end)
task1 = Task.await(task1)
task2 = Task.await(task2)
task3 = Task.await(task3)
case task1 do
{:ok, true} -> task2
{:ok, _} -> false
{:error, _reason} -> task3 && task2
end
end
def get_failed_4G(table) do
query = from(m in table, select: %{msisdn: m.msisdn_2})
items = Repo.stream(query, timeout: :infinity, max_rows: 70)
stream = Task.Supervisor.async_stream_nolink(Lte.TaskSupervisor, items, fn item ->
status = Lte.validate_sim_phone_status(item.msisdn)
if status, do: :do_something
end, timeout: 50_000)
Repo.transaction(fn ->
Stream.run(stream)
end, timeout: :infinity)
end
I was wondering if the tasks defined with the validate_sim_phone_status
will be supervised, is there a better implementation.
Thank you.