Finding ids of children in DynamicSupervisor

I am trying to run a list of tasks under a Dynamic Supervisor. Imagine that it is a URL downloader. I need to know if they are still running, and maybe talk to them to change their configuration in-flight.

In order to talk to them, each task is registered as {Download, "www.example.com"} in a global registry. Now, the application runs a dynamic number of sub-applications, so that there is

  • {DynamicSupervisor “customer-a”}
  • {DynamicSupervisor “customer-b”}

So I basically want to know which Download modules are running under {DynamicSupervisor "customer-a"} - so I call it and get a list of children like:

[{:undefined, #PID<0.14119.0>, :worker, [Downloader]},
{:undefined, #PID<0.14123.0>, :worker, [Downloader]}]

The issue is that only the module is reported back, so I cannot know which one it is - I can get the PID, get all the pids out of Registry, and keep the ones that match both, so I can look up the same information. But this seems quite a mouthful.

Is there a way to change the name of the module in the output, or tag it somehow? The first field is supposed to be the :id and it would be perfect, but in DynamicSupervisor, as per the docs (why?) it is always :Undefined.

1 Like

Can you show how have you defined the DynamicSupervisor in your application file as a start?

I would register tasks with {client_id, url} in the registry.
So you can use Registry.match to filter keys for a given client_id.

Note that you may not need multiple supervisors, you can start all downloaders under the same. Except if your “sub applications” are OTP applications.

1 Like

Take a look at the DynamicSupervisor’s extra_arguments. I use it all the time in combo with a via_tuple function and child_spec function on the children to namespace the child processes within the registry. You could use the customer id for example.

The other option is to manually register the children into another registry during the init with the customer id passed by the extra_argument.

Let me know if you need an example. I’m just on a tablet, or I’d have posted one

1 Like