elixir - 主管树退出而不是重新启动子进程
问题描述
我的问题很像这里描述的Supervision tree failed to start,并且提供的解决方案似乎或多或少与我所拥有的相同,除了我的只是在子进程失败并显示以下消息时退出:** (Mix) Could not start application server: Server.start(:normal, []) returned an error: shutdown: failed to start child: Server.Gen.StartRabbit
。我想知道如何让它“重新启动”(或者更确切地说重试启动,因为它实际上还没有启动)。谢谢!
defmodule Server do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
{
GenRegistry,
worker_module: Server.Gen.Rabbit
},
Server.Gen.StartRabbit,
Plug.Cowboy.child_spec(
scheme: :http,
plug: Server.Router,
options: [
port: String.to_integer(System.get_env("PORT") || "3000"),
dispatch: dispatch(),
protocol_options: [idle_timeout: :infinity]
]
)
]
opts = [strategy: :one_for_one, name: Server.Supervisor]
Supervisor.start_link(children, opts)
end
end
defmodule Server.Gen.StartRabbit do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
def init(_opts) do
Enum.each(0..5, fn x ->
GenRegistry.lookup_or_start(Gen.Rabbit, Integer.to_string(x), [
%Gen.Rabbit.State{id: str_id, chan: nil}
])
end)
{:ok, %{}}
end
end
解决方案
推荐阅读
- maven - 在 Intellij 项目中使用 Nd4j
- ruby-on-rails - 如果最新的迁移相同,Rails 如何知道有待处理的迁移?
- javascript - 需要一个 JSON 对象、数组或文字
- c++ - 在编译时为运行时设置环境变量
- python - 即使安装了 conda 也无法执行 conda 命令
- bash - 作为参数传递给heredoc块内的docker-compose命令时变量不会扩展
- objective-c - 如何获取超类的对象实例
- django - Django cron 作业无法连接到 Elastic Beanstalk 上的数据库
- javascript - webpack splitChunks:如何将依赖项合并到命名块中?
- java - Java 库 Graphics2D 不将文本显示为正确的字体