将第二个 child 添加到主管会引发错误

adding second child to supervisor throws error

我想向我的主管添加第二个 child,但出现以下错误。

**(混合)无法启动应用程序 cloner_worker:退出时间:ClonerWorker.Application.start(:normal, []) ** (EXIT) 引发异常: ** (ArgumentError) 模块 ClonerWorker.Worker 已作为 child 提供给主管,但它不存在。 (长生不老药 1.11.2)lib/supervisor.ex:631: Supervisor.init_child/1 (长生不老药 1.11.2)lib/enum.ex:1399: 枚举。"-map/2-lists^map/1-0-"/2 (长生不老药 1.11.2)lib/supervisor.ex:617: Supervisor.init/2 (长生不老药 1.11.2)lib/supervisor.ex:556: Supervisor.start_link/2 (内核 7.1)application_master.erl:277: :application_master.start_it_old/4

application.ex

defmodule ClonerWorker.Application do
  @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 = [
      # this is the child that is throwing the error
      {ClonerWorker.Worker, []},
      supervisor(
        KafkaEx.ConsumerGroup,
        [genconsumer_impl,genconsumer_group_name,topic_names,genconsumer_group_opts]
      )
    ]

    opts = [strategy: :one_for_one, name: ClonerWorker.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

worker.ex

defmodule ClonerWorker.Worker do
  use GenServer
  use Tesla
  require Logger

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

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

  def init(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

我知道已经有人问过类似的问题,但我在那里找不到解决我的问题的方法

在此先感谢您能为我提供的任何帮助。

问题是我将我的文件命名为 worker.exs 而不是 worker.ex 对于问题中我放置 worker.ex

的误解,我深表歉意