##作ろうとしてるもの
ウェブサイトのクローラーで、スーパーバイズされた各プロセスに、それぞれ担当するウェブサイトを割り当てるもの。
イメージとしては、
親プロセス(監視担当)
プロセス1(Example1.comをクロールする)
プロセス2(Example2.comをクロールする)
という感じです。
##できないこと
Iexに直接コードを入力した場合は、うまくいくのですが、mix runでやろうとすると
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
というエラーがでてしまい、BEAMがただちにクラッシュします。
何をしても解決できないのでお手上げです。
##やったこと
Phoenixなどのコードを読みましたが、分かりません。
##コード
Mix.exs
elixir
1defmodule Crowller.MixProject do 2 use Mix.Project 3 4 def project do 5 [ 6 app: :crowller, 7 version: "0.1.0", 8 elixir: "~> 1.7", 9 start_permanent: true, 10 deps: deps() 11 ] 12 end 13 14 # Run "mix help compile.app" to learn about applications. 15 def application do 16 [ 17 mod: {Crowller.Application, []} 18 ] 19 end 20 21 # Run "mix help deps" to learn about dependencies. 22 defp deps do 23 [ 24 {:poison, "~> 3.1"}, # json library 25 {:httpoison, "~> 1.4"}, # http 26 ] 27 end 28end
elixir
1defmodule Crowller.Application do 2 use Application 3 4 def start(_type, _args) do 5 key_groups = struct(Crowller.Data.ServerList).keygroups 6 7 Supervisor.start_link(children(), strategy: :one_for_one) 8 end 9 10 def children do 11 key_groups = struct(Crowller.Data.ServerList).keygroups 12 13 for index <- 0..length(key_groups)-1 do 14 %{ 15 id: String.to_atom("CrowllerServer#{index}"), 16 start: {Crowller.Server, :start_link, [[Enum.at(key_groups, index)]]} 17 } 18 end 19 end 20 21end 22 23defmodule Crowller.Server do 24 use GenServer 25 26 def start_link(key_group) do 27 GenServer.start_link(__MODULE__, key_group) 28 end 29 30 @impl true 31 def init(key_group) do 32 Task.start_link fn -> 33 Crowller.Controller.matched_group_loop(key_group, 0) 34 end 35 {:ok, key_group} 36 end 37 38end 39
よろしくお願いします。
あなたの回答
tips
プレビュー