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 ?