我正在尝试使用Ecto在我的 Elixir 应用程序中配置两个存储库。
我需要帮助来配置它们,以便使用 one_for_one 策略独立监督它们;我认为这是正确的,这意味着使用它们的进程将重新启动
回购 A 和回购 B
mix.exs 设置:
def application do
[applications: [:logger, :tds, :tds_ecto, :ecto, :httpoison, :csvlixir],
mod: {MyApp, []}]
end
MyApp_app.ex
片段如下:
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
supervisor(MyApp.Repo-A, []),
worker(Task, [MyAppModule, :work, []], restart: :temporary),
supervisor(MyApp.Repo-B, []),
worker(Task, [MyAppModule, :work, []], restart: :temporary)
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
defmodule Repo-A do
use Ecto.Repo, otp_app: :myapp
end
defmodule Repo-B do
use Ecto.Repo, otp_app: :myapp
end
当我mix run
得到以下信息时 - 我不确定如何正确定义id。
** (Mix) Could not start application myapp: exited in: MyApp.start(:normal, [])
** (EXIT) an exception was raised:
** (ArgumentError) duplicated id Task found in the supervisor specification, please explicitly pass the :id option when defining this worker/supervisor