Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow worker name to be separated from process name #416

Open
BlueCollarChris opened this issue Oct 21, 2020 · 5 comments
Open

Allow worker name to be separated from process name #416

BlueCollarChris opened this issue Oct 21, 2020 · 5 comments

Comments

@BlueCollarChris
Copy link

def start_link(args, name) do

Requested

# additional function argument that can contain [name: my_desired_name]
def start_link(args, name, opts) do
    GenServer.start_link(__MODULE__, [args, name], opts)
end

OR

# where args contains the desired worker name
def start_link(args, opts) do
    GenServer.start_link(__MODULE__, [args], opts)
end
@BlueCollarChris
Copy link
Author

If this is something that can be added I would perform the work and open a PR just not sure what you guys are thinking

@joshuawscott
Copy link
Member

This seems like a good idea to me. I think perhaps we could go with the second version where we can extract the name from opts, since normally a GenServer uses a name passed in the final options keyword list.

@dantswain
Copy link
Collaborator

dantswain commented Oct 22, 2020

The name argument was for compatibility with the existing supervisor. I'd have to dig a little to remember why but the tests should fail if anything gets broken too badly.

I think something like this would make sense

def start_link(args, gen_server_opts \\ []) do
  final_args = case Keyword.fetch(gen_server_opts, :name) do
    {:ok, name} -> args ++ [name: name]
    :error -> args
  end
  GenServer.start_link(__MODULE__, [final_args], gen_server_opts)
end

@BlueCollarChris
Copy link
Author

BlueCollarChris commented Nov 16, 2020

Sorry I got sidetracked and forgot to keep up with the thread, but I will take what @dantswain mentioned and go ahead and incorporate that then open PR.

@BlueCollarChris
Copy link
Author

BlueCollarChris commented Nov 16, 2020

Actually doing it that way would then tie the worker name back to the genserver when its not very elegant to have a worker named in a way the genserver may be named. I think they need to be separated completely as the name of the worker and genserver should never cross paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants