Hrukem
How to give a name in child specification supervisor
I made a function that runs as a process. If I start this process and then register it, then my app works fine. But if I run this process in child specifications, the app stops working. The process starts in both cases, but in the second case I can’t contact the process.
defp start_programm(conn_redis) do
pid = spawn_link(TaskTest.WorkWithRedis, :redis_put, [conn_redis])
Process.register(pid, :qqq)
children = [
{
Plug.Cowboy,
scheme: :http,
plug: TaskTest.Router,
options: [port: cowboy_port()]
},
%{
id: ListKeysRedis,
start: {TaskTest.ListKeysRedis, :start, []}
} #,
%{
id: WorkWithRedis,
start: {TaskTest.WorkWithRedis, :redis_put, [conn_redis]},
name: Qqq
}
]
opts = [strategy: :one_for_one, name: TaskTest.Supervisor]
Logger.info("Starting application...")
Supervisor.start_link(children, opts)
end
When I launch the app as above, everything works. But if I comment out the lines
pid = spawn_link(TaskTest.WorkWithRedis, :redis_put, [conn_redis])
Process.register(pid, :qqq)
and uncomment the commented out lines an error occurs when trying to send a message to the process.
How can I run a process under Supervisor and communicate with this process from any part of the code ?
First Post!
LostKobrakai
The child spec does only define a child for a supervisor. It‘s not concerned with process registration. That‘s something the started child process itself would need to handle.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










