Elixir exrm 版本在 eredis 上崩溃 start_link

Elixir exrm release crashes on eredis start_link

我对 Elixir 还很陌生,这是我尝试使用 exrm. My app interacts with a Redis database for consuming jobs from a queue (using exq), and also stores results of processed jobs in Redis using eredis.

发布的第一个应用程序

当我通过 iex -S mix 运行 我的应用程序运行完美时,它在编译成脚本时也 运行 非常好。然而,当我使用 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?

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