本文介绍了Elixir exrm释放在eredis start_link上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常新的Elixir,这是我试图发布的第一个应用程序,使用),还可以存储使用在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',启动,[正常,[]]},{ '退出',{{badmatch,{错误,{{ '退出',{{badmatch,{错误,{是undef,[{eredis,START_LINK,[],[]},{ 'Elixir.MyApp.Cache',INIT,1,[{文件,\ LIB / my_app应用/ cache.ex\},{线, 8}]},{gen_server,init_it,6,[{文件,\ gen_server.erl\},{线,306}]},{proc_lib,init_p_do_apply,3,[{文件,\proc_lib .erl\ },{线,237}]}]}}},[{ 'Elixir.MyApp.Cache',START_LINK,1,[{文件,\ LIB / my_app应用/ cache.ex\ },{线,21}]},{主管,do_start_child,2,[{文件,\ supervisor.erl\},{线,314}]},{主管,handle_start_child,2,[{文件,\ supervisor.erl\},{线,685}]},{主管,handle_call,3,[{文件,\监.erl\ },{线,394}]},{gen_server,try_handle_call,4,[{文件,\ gen_server.erl\},{线,607}]},{gen_server,HANDLE_MSG, 5,[{文件,\ gen_server.erl\},{线,639}]},{proc_lib,init_p_do_apply,3,[{文件,\ proc_lib.erl\},{线, 237}]}]}},{子,未定义 'Elixir.MyApp.Cache',{ 'Elixir.MyApp.Cache',START_LINK,[[{主机,\ 127.0.0.1\},{端口,6379},{数据库,0},{密码,[]},{reconnect_timeout,100},{命名空间,<<>>},{队列,并[d< \elixir\ >>]}]]},永久的,5000,工人,[ 'Elixir.MyApp.Cache']}}}},[{ 'Elixir.MyApp.Supervisor',start_cache,1,[{文件,\\ \\ LIB / my_app应用/ supervisor.ex\},{线,17}]},{ 'Elixir.MyApp.Supervisor',START_LINK,0,[{文件,\LIB / my_app应用/ supervisor.ex\\ \\ },{线,9}]},{ 'Elixir.MyApp',启动,2,[{文件,\ LIB / my_app.ex\},{线,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,
酏剂:〜> 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,标签: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 
使用GenServer

需要Logger

def init(client_opts)do
{:ok,客户端} =: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 函数,以便它与发行版一起打包,这也适用于其余的依赖项。


I'm fairly new to Elixir and this is the first app that I'm attempting to release using 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.

My app works perfectly when I run it via iex -S mix, and it also runs great when compiled into an escript. However when I use exrm, the application compiles without any issue, but it crashes when I run it.

This is the crash output:

$ ./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}]}]}}}}}"}

Here is the mix.exs for my application:

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

The crash appears to be happening in the following init function, where I call :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

Could it be because eredis is an Erlang library as opposed to Elixir?

解决方案

You need to add :eredis to your app_list function, so that it is packaged with the release, that goes for the rest of your dependencies as well.

这篇关于Elixir exrm释放在eredis start_link上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 18:18