I’m trying to shut down my phoenix app when Idle as explained in this blog post, but I want to use ThousandIsland / Bandit.
How can I adapt this snippet using ThousandIsland?
if :ranch.procs(AppWeb.Endpoint.HTTP, :connections) == [] do
System.stop(0)
1 Like
I tried that, but got into these errors:
ThousandIsland.connection_pids(self())
[error] Task #PID<0.908.0> started from Timetask.Supervisor terminating
** (stop) exited in: GenServer.call(#PID<0.908.0>, :which_children, :infinity)
** (EXIT) process attempted to call itself
(elixir 1.14.2) lib/gen_server.ex:1031: GenServer.call/3
(thousand_island 0.6.4) lib/thousand_island/server.ex:22: ThousandIsland.Server.acceptor_pool_supervisor_pid/1
(thousand_island 0.6.4) lib/thousand_island.ex:183: ThousandIsland.connection_pids/1
(elixir 1.14.2) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
(stdlib 4.0) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Function: #Function<0.17788813/0 in Timetask.Application.start/2>
Args: []
ThousandIsland.listener_info(self())
[error] Task #PID<0.918.0> started from Timetask.Supervisor terminating
** (stop) exited in: GenServer.call(#PID<0.918.0>, :which_children, :infinity)
** (EXIT) process attempted to call itself
(elixir 1.14.2) lib/gen_server.ex:1031: GenServer.call/3
(thousand_island 0.6.4) lib/thousand_island/server.ex:13: ThousandIsland.Server.listener_pid/1
(thousand_island 0.6.4) lib/thousand_island.ex:169: ThousandIsland.listener_info/1
(timetask 0.7.0) lib/config/application.ex:45: Timetask.Application.shutdown_when_inactive/1
(elixir 1.14.2) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
(stdlib 4.0) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Function: #Function<0.26013251/0 in Timetask.Application.start/2>
Args: []
I’m completely out of my depth here.
n0gg1n
4
I think you have to use the following
endpoint_pid = Process.whereis(AppWeb.Endpoint)
ThousandIsland.connection_pids(endpoint_pid)
That didn’t help either. I found another post with a solution thou 
1 Like