xgen icon indicating copy to clipboard operation
xgen copied to clipboard

Task.Node

Open fishcakez opened this issue 11 years ago • 6 comments

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.

fishcakez avatar May 01 '14 16:05 fishcakez

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 avatar May 01 '14 16:05 josevalim

@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.

fishcakez avatar May 01 '14 16:05 fishcakez

A slight correction, it would use the same API as Task by calling the Task.Sup API.

fishcakez avatar May 01 '14 16:05 fishcakez

I referenced the wrong issue in the commit. :D

josevalim avatar May 10 '14 13:05 josevalim

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.

fishcakez avatar May 10 '14 18:05 fishcakez

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.

josevalim avatar May 10 '14 18:05 josevalim