How to add a child process in my application.ex?

Yes I tried this. But it’s giving me Gorm.RedisPool.start_link/1 is undefined or private

Make it with one argument,

def start_link(_args) do
    Supervisor.start_link(__MODULE__, [])
  end

Yes, my mistake, sorry. I had a long day :wink: I think I confused you. See @GokulSubramaniam’s answer: you are missing the argument in start_link

Nice. But this is saying

Gorm.RedisPool.init/1 returned a bad value: {:ok, #PID<0.453.0>}

No problem man. Thanks for helping

It worked. Did a silly mistake

This would happen if you follow my wrong previous advise and use Supervisor.start_link instead of Supervisor.init inside Gorm.RedisPool.init. It is correct to call Supervisor.init there, as you previously did.

1 Like

Yes I did see that. Thanks

Hey I’m trying to call this function RedisPool.start_link function in my terminal but it’s not working or giving me this error

(UndefinedFunctionError) function Gorm.RedisPool.start_link/0 is undefined or private. Did you mean one of:

      * start_link/1

    (gorm) Gorm.RedisPool.start_link()

I don’t understand why

Got it. No problem

What do you mean “in your terminal”? You mean in iex?

Yes, there is no RedisPool.start_link/0 anymore, you made it a /1, you need to provide an argument.

Yes iex. Also I did that.

After the fix from @GokulSubramaniam, the start_link function takes one argument. You can either call it like Gorm.RedisPool.start_link([]), or define it with a default argument:

def start_link(args \\ []) do
  Supervisor.start_link(__MODULE__, args)
end

Also see my response above regarding understanding the UndefinedFunctionError.

Yes, I did this.

RedisPool.start_link([])        
** (EXIT from #PID<0.466.0>) shell process exited with reason: shutdown: failed to start child: :redix_poolboy
    ** (EXIT) already started: #PID<0.444.0>

Dealing with this right now

Also, thanks for assigning me the correct answer, but I think @GokulSubramaniam or @NobbZ answer should be marked as the correct one, as their answers correctly described the two fixes needed in the original code :slight_smile:

As the error says, the process was already started. Since you are giving a name to your RedisPool process (the name part in Supervisor.init(children, strategy: :one_for_one, name: __MODULE__)), only one process with that name can be running at the same time, even in your IEx.

Either close and reopen your IEx, or stop the previously running process with Supervisor.stop(Gorm.RedisPool) before starting it again.

No, I’m not talking about this

Why this is failing?

As @lucaong already pointed out, you can’t start 2 processes with the same name, that’s why it’s crashing.

Your iex crashes, because a linked process crashed. That’s what start_link does.

Is the process still running even if I close the terminal? Because everytime I’m trying to start a new process it’s giving me the same error

How do you start your terminal? iex -S mix? This will start your application as well.