Last active
July 27, 2019 14:26
-
-
Save chazsconi/089f94d87d1fd5fe1c1a95fb4ca20ddf to your computer and use it in GitHub Desktop.
Handling long polling and trapping shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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