Having issue in adding supervisor to my phoenix app

I have a Phoenix App - what I am trying to achieve is:

  • Endpoints
  • Each-Endpoints will have their own process
  • GenServer to handle those process
  • Supervisor to handle this server
defmodule ApiWeb.Supervisor do
  use Application

  def start(_type, _args) do
    children = [
      {ApiWeb.Servers.Analytics, :start_link, %{}}
    ]

    opts = [strategy: :rest_for_one, name: SequenceSuper.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
defmodule ApiWeb.Servers.Analytics do
  use GenServer, restart: :transient

  @analytics __MODULE__

  def start_link(args) do
    GenServer.start_link(@analytics, args, name: @analytics)
  end

  def recently_updated_list() do
    GenServer.call(@analytics, {:get_recently_updated})
  end
end

and controller functions that will call functions from Servers

Now i am getting an error like

If you application was generated by mix phx.new api I believe your top supervisor is in the Api.Application module, not ApiWeb.Application. Did you create this one yourself ?

2 Likes

Yes I created this manually

Is this supervisor called somewhere ?

Show us your application/0 function in mix.exs.

I found the issue, issue was with the placement of code, actually i have to create supervisor in Api instead it was created in ApiWeb. Thanks guys for the help.

2 Likes