RafaelBackx

RafaelBackx

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 https://hexdocs.pm/elixir/Application.html
  # 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 = [
      ClonerWorker.Worker,
      supervisor(
        KafkaEx.ConsumerGroup,
        [genconsumer_impl,genconsumer_group_name,topic_names,genconsumer_group_opts]
      )
      # Starts a worker by calling: ClonerWorker.Worker.start_link(arg)
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: ClonerWorker.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

this is my module worker.ex

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

  @base_url "https://poloniex.com/public?command=returnTradeHistory"

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

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

  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
      Logger.info("Result is lesser than 1000")
      for item <- result do
        IO.inspect(item)
      end
    else
      Logger.warn("Result is greater than 1000")
    end
  end

  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-SIGN",sign},
               {"PF-API-TIMESTAMP",timestamp},
               {"PF-API-PASSPHRASE", passphrase}]
    {:ok, result} = Tesla.get(url,headers)
    Logger.info(result.status)
    result = Jason.decode!(result.body)
  end

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

thanks in advance for any help you can offer me

Showing Posts 1 to 7

hubertlepicki

hubertlepicki

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

RafaelBackx

RafaelBackx OP

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

hubertlepicki

hubertlepicki

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

RafaelBackx

RafaelBackx OP

An explaination would be great thank you

hubertlepicki

hubertlepicki

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.

CafeRacer

CafeRacer

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

hubertlepicki

hubertlepicki

Live long and prosper, my friend.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews