Skip to content

Instantly share code, notes, and snippets.

@chazsconi
Last active July 27, 2019 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chazsconi/089f94d87d1fd5fe1c1a95fb4ca20ddf to your computer and use it in GitHub Desktop.
Save chazsconi/089f94d87d1fd5fe1c1a95fb4ca20ddf to your computer and use it in GitHub Desktop.
Handling long polling and trapping shutdown
def wait(conn, _params) do
Logger.info("start - #{inspect(self())}")
Logger.info("Sleeping...")
Process.flag(:trap_exit, true)
result =
receive do
{:EXIT, _caller, :shutdown} ->
Logger.info("Got shutdown")
:shutdown
after
20_000 ->
:timeout
end
# Need to reset flag as the process is recycled
Process.flag(:trap_exit, false)
Logger.info("Replying")
conn
|> text("OK - #{inspect(self())} #{inspect(result)}")
end
#!/bin/bash
pid=$(ps aux | grep beam | grep phx | awk '{print $2}') ; kill -s TERM $pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment