Error when adding a second child to my Supervisor

i am trying to add a second module to my supervisor but i get the following error:

** (Mix) Could not start application cloner_worker: exited in: ClonerWorker.Application.start(:normal, [])
** (EXIT) an exception was raised:
** (ArgumentError) The module ClonerWorker.Worker was given as a child to a supervisor but it does not exist.
(elixir 1.11.2) lib/supervisor.ex:631: Supervisor.init_child/1
(elixir 1.11.2) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
(elixir 1.11.2) lib/supervisor.ex:617: Supervisor.init/2
(elixir 1.11.2) lib/supervisor.ex:556: Supervisor.start_link/2
(kernel 7.1) application_master.erl:277: :application_master.start_it_old/4

this is my application.ex

defmodule ClonerWorker.Application do
  # See
  # for more information on OTP Applications
  @moduledoc false

  use Application
  import Supervisor.Spec

  def start(_type, _args) do
    genconsumer_impl = ClonerWorker
    genconsumer_group_name = "cloners"
    genconsumer_group_opts = []
    topic_names = ["todo-chunks"]

    children = [
      # Starts a worker by calling: ClonerWorker.Worker.start_link(arg)

    # See
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: ClonerWorker.Supervisor]
    Supervisor.start_link(children, opts)

this is my module worker.ex

defmodule ClonerWorker.Worker do
  use GenServer
  use Tesla
  require Logger
  require IEx

  @base_url ""

  def start_link(_module,args) do
    GenServer.start_link(__MODULE__, args, name: __MODULE__)

  def init(_module,args) do
    {:ok, args}

  def get_history_for(currency_pair, from_unix, until_unix) do
    from_unix = from_unix * 1000
    until_unix = until_unix * 1000
    url = "#{url}&currencyPair=#{currency_pair}&start=#{from_unix}&end=#{until_unix}"
    result = send_request(url)
    if (Enum.count(result) < 1000) do"Result is lesser than 1000")
      for item <- result do
      Logger.warn("Result is greater than 1000")

  defp send_request(url) do
    timestamp = DateTime.to_unix(DateTime.utc_now())
    key = Application.get_env(:cloner_worker,:key)
    secret = Application.get_env(:cloner_worker,:secret)
    passphrase = Application.get_env(:cloner_worker,:passphrase)
    sign = sign(key,timestamp,url)
    headers = [{"PF-API-KEY",key},
               {"PF-API-PASSPHRASE", passphrase}]
    {:ok, result} = Tesla.get(url,headers)
    result = Jason.decode!(result.body)

  defp sign(key, timestamp, endpoint, method \\ "GET", body \\ "") do
    value = "#{timestamp}#{method}#{endpoint}#{body}"
    :crypto.hmac(:sha256, key,value) |> Base.encode64

thanks in advance for any help you can offer me

Just double checking here, your file containing worker has “.ex” extension? Not “.exs” by accident?

1 Like

you are right the extension is indeed .exs i just changed it, thanks

1 Like

Do you know why it worked or should I provide quick explanation?

An explaination would be great thank you

Ugh, sorry for missing this one.

.ex - is the extension of Elixir files that are to be compiled before running program. If you run mix compile these files will be compiled.

.exs - it’s the extension of Elixir files that are to be executed as scripts, i.e. they are compiled as they are being loaded/executed and not before.

If you put a module in .ex file it will be then compiled along with rest of application, and resulting .beam file will be loaded to virtual machine. .exs file won’t be loaded at all.

As a rule of thumb, in Elixir projects things like tests or mix files are .exs, and everything else is .ex.


Thank you @hubertlepicki , you saved me too, a few minutes.

1 Like

Live long and prosper, my friend.