From ec58d9f4075a5600555246807001c64fe38b8d03 Mon Sep 17 00:00:00 2001 From: Eric Oestrich Date: Wed, 9 Aug 2023 09:09:38 -0400 Subject: [PATCH] Remove the watcher server It doesn't function in nerves and is very flaky to begin with, it's just better to launch node or whatever outside of the beam. --- lib/aino/watcher.ex | 86 --------------------------------------------- mix.exs | 1 - mix.lock | 1 - 3 files changed, 88 deletions(-) delete mode 100644 lib/aino/watcher.ex diff --git a/lib/aino/watcher.ex b/lib/aino/watcher.ex deleted file mode 100644 index 2dcf5ff..0000000 --- a/lib/aino/watcher.ex +++ /dev/null @@ -1,86 +0,0 @@ -defmodule Aino.Watcher do - @moduledoc """ - Launch external processes along with the Aino - - Example: - - ``` - watchers = [ - [ - command: "node_modules/yarn/bin/yarn", - args: ["build:js:watch"], - directory: "assets/" - ], - [ - command: "node_modules/yarn/bin/yarn", - args: ["build:css:watch"], - directory: "assets/" - ] - ] - - children = [ - {Aino.Watcher, name: MyApp.Watcher, watchers: watchers} - ] - ``` - """ - - use Supervisor - - def start_link(opts) do - Supervisor.start_link(__MODULE__, opts) - end - - def init(opts) do - children = - opts[:watchers] - |> Enum.with_index() - |> Enum.map(fn {watcher, index} -> - Supervisor.child_spec({Aino.Watcher.ExternalProcess, watcher}, id: {__MODULE__, index}) - end) - - opts = [strategy: :one_for_one, name: opts[:name]] - Supervisor.init(children, opts) - end -end - -defmodule Aino.Watcher.ExternalProcess do - @moduledoc false - - use GenServer - - def start_link(opts) do - GenServer.start_link(__MODULE__, opts) - end - - def init(opts) do - opts = Enum.into(opts, %{}) - - {:ok, opts, {:continue, :spawn}} - end - - def handle_continue(:spawn, state) do - command_directory = Path.join(File.cwd!(), state.directory) - command = Path.join(command_directory, state.command) - - {:ok, _pid, external_pid} = - :exec.run_link([command | state.args], [ - {:cd, command_directory}, - {:stdout, self()}, - {:stderr, self()} - ]) - - {:noreply, Map.put(state, :external_pid, external_pid)} - end - - def handle_info({:stdout, pid, output}, %{external_pid: pid} = state) do - IO.puts(output) - - {:noreply, state} - end - - def handle_info({:stderr, pid, output}, %{external_pid: pid} = state) do - IO.puts(output) - - {:noreply, state} - end -end diff --git a/mix.exs b/mix.exs index 7b1c618..beed4d1 100644 --- a/mix.exs +++ b/mix.exs @@ -59,7 +59,6 @@ defmodule Aino.MixProject do [ {:credo, "~> 1.5", only: [:dev, :test]}, {:elli, "~> 3.3"}, - {:erlexec, "~> 1.0"}, {:ex_doc, "~> 0.28.0", only: [:dev]}, {:jason, "~> 1.2"}, {:mime, "~> 2.0"} diff --git a/mix.lock b/mix.lock index 031e3f0..c78303e 100644 --- a/mix.lock +++ b/mix.lock @@ -3,7 +3,6 @@ "credo": {:hex, :credo, "1.6.4", "ddd474afb6e8c240313f3a7b0d025cc3213f0d171879429bf8535d7021d9ad78", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "c28f910b61e1ff829bffa056ef7293a8db50e87f2c57a9b5c3f57eee124536b7"}, "earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"}, "elli": {:hex, :elli, "3.3.0", "089218762a7ff3d20ae81c8e911bd0f73ee4ee0ed85454226d1fc6b4fff3b4f6", [:rebar3], [], "hexpm", "698b13b33d05661db9fe7efcba41b84825a379cce86e486cf6aff9285be0ccf8"}, - "erlexec": {:hex, :erlexec, "1.19.1", "bdd10c4f6c5f3c5c9aa31f5293681b128fab4a25a750119ef07a65f376f3c2ce", [:rebar3], [], "hexpm", "03597ae9140b4e62009e94ba0a0bbf481560146069a90a3eacd32774ea348fd0"}, "ex_doc": {:hex, :ex_doc, "0.28.3", "6eea2f69995f5fba94cd6dd398df369fe4e777a47cd887714a0976930615c9e6", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "05387a6a2655b5f9820f3f627450ed20b4325c25977b2ee69bed90af6688e718"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},