【问题标题】:Elixir exrm release crashes on eredis start_linkElixir exrm 版本在 eredis start_link 上崩溃
【发布时间】:2023-03-18 17:18:01
【问题描述】:

我对 Elixir 还很陌生,这是我尝试使用 exrm 发布的第一个应用程序。我的应用程序与 Redis 数据库交互以使用队列中的作业(使用 exq),并且还使用 eredis 将已处理作业的结果存储在 Redis 中。

当我通过iex -S mix 运行我的应用程序时,它运行良好,并且在编译成 escript 时它也运行良好。但是,当我使用 exrm 时,应用程序编译没有任何问题,但是当我运行它时它崩溃了。

这是崩溃输出

$ ./rel/my_app/bin/my_app console
{"Kernel pid terminated",application_controller,"{application_start_failure,my_app,{bad_return,{{'Elixir.MyApp',start,[normal,[]]},{'EXIT',{{badmatch,{error,{{'EXIT',{{badmatch,{error,{undef,[{eredis,start_link,[],[]},{'Elixir.MyApp.Cache',init,1,[{file,\"lib/my_app/cache.ex\"},{line,8}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,306}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,237}]}]}}},[{'Elixir.MyApp.Cache',start_link,1,[{file,\"lib/my_app/cache.ex\"},{line,21}]},{supervisor,do_start_child,2,[{file,\"supervisor.erl\"},{line,314}]},{supervisor,handle_start_child,2,[{file,\"supervisor.erl\"},{line,685}]},{supervisor,handle_call,3,[{file,\"supervisor.erl\"},{line,394}]},{gen_server,try_handle_call,4,[{file,\"gen_server.erl\"},{line,607}]},{gen_server,handle_msg,5,[{file,\"gen_server.erl\"},{line,639}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,237}]}]}},{child,undefined,'Elixir.MyApp.Cache',{'Elixir.MyApp.Cache',start_link,[[{host,\"127.0.0.1\"},{port,6379},{database,0},{password,[]},{reconnect_timeout,100},{namespace,<<>>},{queues,[<<\"elixir\">>]}]]},permanent,5000,worker,['Elixir.MyApp.Cache']}}}},[{'Elixir.MyApp.Supervisor',start_cache,1,[{file,\"lib/my_app/supervisor.ex\"},{line,17}]},{'Elixir.MyApp.Supervisor',start_link,0,[{file,\"lib/my_app/supervisor.ex\"},{line,9}]},{'Elixir.MyApp',start,2,[{file,\"lib/my_app.ex\"},{line,10}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}

这是我的应用程序的 mix.exs

defmodule MyApp.Mixfile do
  use Mix.Project

  def project do
    [
      app: :my_app,
      version: "0.0.1",
      name: "MyApp",
      elixir: "~> 1.0",
      escript: escript_config,
      deps: deps
    ]
  end

  def application do
    [
      applications: app_list(Mix.env),
      mod: { MyApp, [] },
      env: [ queue: 'elixir']
    ]
  end

  def included_applications do
    [ :logger, :httpoison, :eredis, :exq, :dotenv, :exjsx, :ex_doc, :oauth2, :sweet_xml ]
  end

  defp app_list(:dev), do: [:dotenv | app_list]
  defp app_list(_), do: app_list
  defp app_list, do: [:logger, :httpoison]

  def escript_config do
    [ main_module: MyApp ]
  end

  defp deps do
    [
      { :dotenv, github: "avdi/dotenv_elixir" },
      { :eredis, github: "wooga/eredis", tag: "v1.0.5" },
      { :exjsx, "~> 3.1.0" },
      { :exq, "~> 0.1.0", app: false },
      { :exrm, "~> 0.16.0" },
      { :ex_doc, github: "elixir-lang/ex_doc" },
      { :httpoison, "~> 0.4" },
      { :oauth2, "~> 0.1.1" },
      { :sweet_xml, "~> 0.2.1" }
    ]
  end
end

崩溃似乎发生在以下 init 函数中,我在其中调用 :eredis.start_link

defmodule MyApp.Cache do
  use GenServer

  require Logger

  def init(client_opts) do
    { :ok, client } = :eredis.start_link(
        client_opts[:host],
        client_opts[:port],
        client_opts[:database],
        client_opts[:password],
        client_opts[:reconnect_timeout])
  end
end

可能是因为 eredis 是 Erlang 库而不是 Elixir?

【问题讨论】:

    标签: erlang elixir exrm


    【解决方案1】:

    您需要将 :eredis 添加到您的 app_list 函数中,以便它与发行版一起打包,这也适用于您的其余依赖项。

    【讨论】:

    • 谢谢@bitwalker,我最终做的是添加一个包含:eredisincluded_applications 列表,并将其添加到application() 返回的字典中。我还需要在此列表中添加一些依赖项的依赖项。我使用的许多 Elixir 软件包似乎都没有配置为开箱即用的 exrm。
    猜你喜欢
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 2017-02-17
    • 1970-01-01
    • 2021-08-09
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多