xgen
xgen copied to clipboard
Task.Node
Tasks can only be created on other nodes if they are supervised. Could xgen provide a task supervisor on each node started with:
Task.Sup.start_link(local: Task.Node)
Task.Node would have the Task.Sup API (except no documented start_link) but take a node name as the first argument instead of a pid/name. For example:
Task.Node.async(node_name, fn() -> :ok end)
Implemented as:
defp async(node_name, task) do
Task.Sup.async({__MODULE__, node_name}, task)
end
This would allow :rpc like functionality "for free" on all nodes.
Is there a benefit to have all of them through the same supervisor? Wouldn't it be better if every application that needs to spawn in remote nodes create their own, specific supervisor?
@josevalim yes it would be better if you are planning alot of tasks. However this is useful for running a task in the shell while developing/testing or to run a status gathering function on all nodes in a cluster. Its likely that the supervisor won't exist because you don't know you need it until its too late.
A slight correction, it would use the same API as Task by calling the Task.Sup API.
I referenced the wrong issue in the commit. :D
Ah I thought this had been rejected. Did you decide on this?
I think it is better to have a Task.Supervisor inside an application, so that it is known that the application is in a suitable state to run the task and allows choosing the correct shutdown strategy. It also means a busy application won't slow down another application because one supervisor is not spawning all the tasks.
However a one off task, maybe in the shell or debugging it might be nice to be able to run a task on another node and not have to start a supervisor.
I did not decide on this yet because we already have the :rpc module and Task.Supervisor. I understand the benefits of Task.Node but they seem to be too small to justify it.