Cleanup
This commit is contained in:
parent
6186331fe8
commit
8c58ecd057
2 changed files with 14 additions and 14 deletions
|
@ -214,6 +214,7 @@ defmodule GenMagic.Server do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def starting(:info, {port, {:exit_status, code}}, %{port: port} = data) do
|
def starting(:info, {port, {:exit_status, code}}, %{port: port} = data) do
|
||||||
error =
|
error =
|
||||||
case code do
|
case code do
|
||||||
|
@ -226,6 +227,7 @@ defmodule GenMagic.Server do
|
||||||
{:stop, {:error, error}, data}
|
{:stop, {:error, error}, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def loading(:enter, _old_state, data) do
|
def loading(:enter, _old_state, data) do
|
||||||
databases =
|
databases =
|
||||||
Enum.flat_map(List.wrap(data.database_patterns || @database_patterns), fn
|
Enum.flat_map(List.wrap(data.database_patterns || @database_patterns), fn
|
||||||
|
@ -243,14 +245,17 @@ defmodule GenMagic.Server do
|
||||||
{:keep_state, {databases, data}, {:state_timeout, 0, :load}}
|
{:keep_state, {databases, data}, {:state_timeout, 0, :load}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def loading(:state_timeout, :load_timeout, {[database | _], data}) do
|
def loading(:state_timeout, :load_timeout, {[database | _], data}) do
|
||||||
{:stop, {:error, {:database_loading_timeout, database}}, data}
|
{:stop, {:error, {:database_loading_timeout, database}}, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def loading(:state_timeout, :load, {[], data}) do
|
def loading(:state_timeout, :load, {[], data}) do
|
||||||
{:next_state, :available, data}
|
{:next_state, :available, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def loading(:state_timeout, :load, {[database | databases], data} = state) do
|
def loading(:state_timeout, :load, {[database | databases], data} = state) do
|
||||||
command =
|
command =
|
||||||
case database do
|
case database do
|
||||||
|
@ -262,6 +267,7 @@ defmodule GenMagic.Server do
|
||||||
{:keep_state, state, {:state_timeout, data.startup_timeout, :load_timeout}}
|
{:keep_state, state, {:state_timeout, data.startup_timeout, :load_timeout}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def loading(:info, {port, {:data, response}}, {[database | databases], %{port: port} = data}) do
|
def loading(:info, {port, {:data, response}}, {[database | databases], %{port: port} = data}) do
|
||||||
case :erlang.binary_to_term(response) do
|
case :erlang.binary_to_term(response) do
|
||||||
{:ok, :loaded} ->
|
{:ok, :loaded} ->
|
||||||
|
@ -269,6 +275,7 @@ defmodule GenMagic.Server do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def loading(:info, {port, {:exit_status, 1}}, {[database | _], %{port: port} = data}) do
|
def loading(:info, {port, {:exit_status, 1}}, {[database | _], %{port: port} = data}) do
|
||||||
{:stop, {:error, {:database_not_found, database}}, data}
|
{:stop, {:error, {:database_not_found, database}}, data}
|
||||||
end
|
end
|
||||||
|
@ -289,6 +296,7 @@ defmodule GenMagic.Server do
|
||||||
{:keep_state_and_data, response}
|
{:keep_state_and_data, response}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def available(:enter, _old_state, %{request: nil}) do
|
def available(:enter, _old_state, %{request: nil}) do
|
||||||
:keep_state_and_data
|
:keep_state_and_data
|
||||||
end
|
end
|
||||||
|
@ -307,6 +315,7 @@ defmodule GenMagic.Server do
|
||||||
{:next_state, :processing, data}
|
{:next_state, :processing, data}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def available({:call, from}, {:reload, databases}, data) do
|
def available({:call, from}, {:reload, databases}, data) do
|
||||||
send(data.port, {:reload, :reload})
|
send(data.port, {:reload, :reload})
|
||||||
|
|
||||||
|
@ -318,6 +327,7 @@ defmodule GenMagic.Server do
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def available({:call, from}, {:recycle, databases}, data) do
|
def available({:call, from}, {:recycle, databases}, data) do
|
||||||
{:next_state, :recycling,
|
{:next_state, :recycling,
|
||||||
%{
|
%{
|
||||||
|
@ -376,16 +386,19 @@ defmodule GenMagic.Server do
|
||||||
handle_status_call(from, :recycling, data)
|
handle_status_call(from, :recycling, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
# In case of timeout, force close.
|
# In case of timeout, force close.
|
||||||
def recycling(:state_timeout, :stop, data) do
|
def recycling(:state_timeout, :stop, data) do
|
||||||
Kernel.send(data.port, {self(), :close})
|
Kernel.send(data.port, {self(), :close})
|
||||||
{:keep_state_and_data, {:state_timeout, data.startup_timeout, :close}}
|
{:keep_state_and_data, {:state_timeout, data.startup_timeout, :close}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def recycling(:state_timeout, :close, data) do
|
def recycling(:state_timeout, :close, data) do
|
||||||
{:stop, {:error, :port_close_failed}}
|
{:stop, {:error, :port_close_failed}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def recycling(:info, {port, :closed}, %{port: port} = data) do
|
def recycling(:info, {port, :closed}, %{port: port} = data) do
|
||||||
{:next_state, :starting, %{data | port: nil, cycles: 0}}
|
{:next_state, :starting, %{data | port: nil, cycles: 0}}
|
||||||
end
|
end
|
||||||
|
@ -401,6 +414,7 @@ defmodule GenMagic.Server do
|
||||||
Kernel.send(port, {self(), :close})
|
Kernel.send(port, {self(), :close})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
def terminate(_, _, _) do
|
def terminate(_, _, _) do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,20 +32,6 @@ defmodule GenMagic.ApprenticeTest do
|
||||||
assert_receive {^port, {:exit_status, 1}}
|
assert_receive {^port, {:exit_status, 1}}
|
||||||
end
|
end
|
||||||
|
|
||||||
# test "exits with a non existent database" do
|
|
||||||
# opts = [
|
|
||||||
# {:args, ["--database-file", "/no/such/database"]},
|
|
||||||
# :use_stdio,
|
|
||||||
# :binary,
|
|
||||||
# :exit_status,
|
|
||||||
# {:packet, 2}
|
|
||||||
# ]
|
|
||||||
#
|
|
||||||
# port = Port.open(GenMagic.Config.get_port_name(), opts)
|
|
||||||
# on_exit(fn() -> send(port, {self(), :close}) end)
|
|
||||||
# assert_receive {^port, {:exit_status, 3}}
|
|
||||||
# end
|
|
||||||
|
|
||||||
describe "port" do
|
describe "port" do
|
||||||
setup do
|
setup do
|
||||||
port = Port.open(GenMagic.Config.get_port_name(), GenMagic.Config.get_port_options([]))
|
port = Port.open(GenMagic.Config.get_port_name(), GenMagic.Config.get_port_options([]))
|
||||||
|
|
Loading…
Reference in a new issue