summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames Every <devstopfix@gmail.com>2019-07-03 21:42:44 +0100
committerJames Every <devstopfix@gmail.com>2019-07-03 22:06:00 +0100
commit724f8a06cde05ddb04b3a410d0326c0372148588 (patch)
tree4fd32802c727892b4c217229b89290c184abb024 /lib
parentPrototype using erlexec (diff)
chore: format
Diffstat (limited to 'lib')
-rw-r--r--lib/gen_magic.ex4
-rw-r--r--lib/gen_magic/apprentice_server.ex22
-rw-r--r--lib/gen_magic/configuration.ex6
3 files changed, 19 insertions, 13 deletions
diff --git a/lib/gen_magic.ex b/lib/gen_magic.ex
index 3711dfa..93b3545 100644
--- a/lib/gen_magic.ex
+++ b/lib/gen_magic.ex
@@ -14,14 +14,14 @@ defmodule GenMagic do
:ok = GenServer.stop(pid)
result
end
-
+
def perform_infinite(path) do
{:ok, pid} = __MODULE__.ApprenticeServer.start_link()
perform_infinite(path, pid)
end
defp perform_infinite(path, pid, count \\ 0) do
- IO.inspect [count, GenServer.call(pid, {:perform, path})]
+ IO.inspect([count, GenServer.call(pid, {:perform, path})])
perform_infinite(path, pid, count + 1)
end
end
diff --git a/lib/gen_magic/apprentice_server.ex b/lib/gen_magic/apprentice_server.ex
index 5aee590..815d14f 100644
--- a/lib/gen_magic/apprentice_server.ex
+++ b/lib/gen_magic/apprentice_server.ex
@@ -31,8 +31,10 @@ defmodule GenMagic.ApprenticeServer do
case {run(path, state), state.count + 1} do
{{:error, :worker_failure} = reply, _} ->
{:reply, reply, stop(state)}
+
{reply, ^max_count} ->
{:reply, reply, stop(state)}
+
{reply, count} ->
{:reply, reply, %{state | count: count}}
end
@@ -55,8 +57,9 @@ defmodule GenMagic.ApprenticeServer do
receive do
{:stdout, ^ospid, "ok\n"} -> {:ok, state}
{:stdout, ^ospid, "ok\r\n"} -> {:ok, state}
- after worker_timeout ->
- {:error, :worker_failure}
+ after
+ worker_timeout ->
+ {:error, :worker_failure}
end
end
@@ -72,15 +75,19 @@ defmodule GenMagic.ApprenticeServer do
receive do
{stream, ^ospid, message} ->
handle_response(stream, message)
- after worker_timeout ->
- {:error, :worker_failure}
+ after
+ worker_timeout ->
+ {:error, :worker_failure}
end
end
defp handle_response(:stdout, "ok; " <> message) do
- case message |> String.trim |> String.split("\t") do
- [mime_type, encoding, content] -> {:ok, [mime_type: mime_type, encoding: encoding, content: content]}
- _ -> {:error, :malformed_response}
+ case message |> String.trim() |> String.split("\t") do
+ [mime_type, encoding, content] ->
+ {:ok, [mime_type: mime_type, encoding: encoding, content: content]}
+
+ _ ->
+ {:error, :malformed_response}
end
end
@@ -96,5 +103,4 @@ defmodule GenMagic.ApprenticeServer do
# (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
# (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
# Last message: {:stderr, 12304, "\n"}
-
end
diff --git a/lib/gen_magic/configuration.ex b/lib/gen_magic/configuration.ex
index b815aad..15334e2 100644
--- a/lib/gen_magic/configuration.ex
+++ b/lib/gen_magic/configuration.ex
@@ -3,12 +3,12 @@ defmodule GenMagic.Configuration do
Convenience module which returns information from configuration.
"""
- @otp_app Mix.Project.config[:app]
+ @otp_app Mix.Project.config()[:app]
def get_worker_command do
database_paths = get_database_paths()
worker_path = Path.join(:code.priv_dir(@otp_app), get_worker_name())
- worker_arguments = Enum.map(database_paths, & "--file " <> &1)
+ worker_arguments = Enum.map(database_paths, &("--file " <> &1))
Enum.join([worker_path | worker_arguments], " ")
end
@@ -19,7 +19,7 @@ defmodule GenMagic.Configuration do
def get_worker_timeout do
get_env(:worker_timeout)
end
-
+
def get_recycle_threshold do
get_env(:recycle_threshold)
end