【发布时间】:2016-03-15 22:29:27
【问题描述】:
我正在尝试使用 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
【问题讨论】:
-
我认为这个问题与 Ecto 无关,难道不是两次调用
worker(Task, [MyAppModule, :work, []], restart: :temporary),的结果吗? -
@Gazler - 是的,同意 Ecto 不是问题 - 只是我的菜鸟使用它:) 我不确定如何为两个 repos 配置主管和工作人员 - 我确定我的帖子代码错误...
标签: elixir erlang-supervisor ecto