1

Ectoを使用して、Elixir アプリで 2 つのリポジトリを構成しようとしています。
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

次の結果が得られた場合、 IDを正しくmix run定義する方法がわかりません。

** (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
4

1 に答える 1

4

idたとえば、引数をキーワード リストに追加optsします。

worker(Task, [MyAppModule, :work, []], restart: :temporary, id: :my_app_module_1)
于 2016-03-15T14:29:27.680 に答える