我可以在 elixir 上运行应用程序,但如果发生错误,一切都会存在。我只想在这种情况下重新启动我的应用程序。我正在使用主管,但甚至不知道它是否有效。以下是我的代码:-
mix.exs:-
def application do
[
applications: [:httpotion, :zookeeper, :parallel, :poison],
mod: {ServiceMonitor, []}
]
end
service_monitor.ex
defmodule ServiceMonitor do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(ServiceMonitor.Registry.setup, []),
]
supervise(children, strategy: :one_for_one)
end
end
注册表.ex
defmodule ServiceMonitor.Registry do
def setup do
zk = get_zk
start(zk)
end
def start(zk) do
#main code
end
end
现在我正在使用以下命令运行我的应用程序:-
MIX_ENV=test mix run
这一切都运行良好,直到我在我的主代码中收到错误。应用程序存在并且永远不会重新启动。我收到的错误是:-
** (Mix) Could not start application service_monitor: exited in: ServiceMonitor.start(:normal, [])
** (EXIT) exited in: Task.await(%Task{owner: #PID<0.164.0>, pid: #PID<0.169.0>, ref: #Reference<0.0.2.1026>}, 3600000)
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, :no_node}
(service_monitor) lib/service_monitor/registry.ex:121: anonymous fn/3 in ServiceMonitor.Registry.remove_available_if_not_registered/3
(elixir) lib/task/supervised.ex:89: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:40: Task.Supervised.reply/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
请帮助我在哪里出错。我的要求是应用程序应在收到错误后立即自动重启。