defmodule WalletValueSupervisor do
use Supervisor
def start_link() do
Supervisor.start_link(__MODULE__, name: __MODULE__)
end
def init(_) do
children = [
worker(WalletValue, [], restart: :permanent)
]
Supervisor.init(children, strategy: :one_for_one)
end
end
defmodule WalletValue do
use GenServer
@tenth_of_a_second 100
@one_second 1000
def start_link() do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
@impl true
def init(opts) do
start_up()
Process.send_after(self(), :tick, @one_second)
{:ok, opts}
end
@impl true
def handle_info(:tick, _state) do
main()
Process.send_after(self(), :tick, @tenth_of_a_second)
{:noreply, :running}
end
iex(1)> WalletValueSupervisor.start_link
runs perfectly fine for a few minutes until:
14:57:25.554 [error] GenServer WalletValue terminating
** (Jason.DecodeError) unexpected byte at position 0: 0x3C ('<')
(jason 1.2.1) lib/jason.ex:78: Jason.decode!/2
(arbit 0.1.0) lib/Wallet.ex:15: Wallet.assets/0
(arbit 0.1.0) lib/Wallet.ex:61: Wallet.account/0
(arbit 0.1.0) lib/Wallet.ex:88: Wallet.reformat/0
(arbit 0.1.0) lib/WalletValue.ex:26: WalletValue.handle_info/2
(stdlib 3.13.2) gen_server.erl:680: :gen_server.try_dispatch/4
(stdlib 3.13.2) gen_server.erl:756: :gen_server.handle_msg/6
(stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: :tick
State: :running
** (EXIT from #PID<0.341.0>) shell process exited with reason: shutdown
What do I need to add/modify in defmodule WalletValueSupervisor
to restart GenServer WalletValue
after shutdown?