Created
May 8, 2023 20:27
-
-
Save axelson/8428c4cbbcbf6d38743e91c9ed48aa01 to your computer and use it in GitHub Desktop.
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
defmodule MyApp.PresenceDrainer do | |
use GenServer | |
require Logger | |
def start_link(opts \\\\ []) do | |
GenServer.start_link(__MODULE__, opts, name: __MODULE__) | |
end | |
@impl GenServer | |
def init(_init_arg) do | |
# We need to trap exits so that we receive the `terminate/2` callback during | |
# a graceful shutdown | |
Process.flag(:trap_exit, true) | |
{:ok, []} | |
end | |
# NOTE: We cannot guarantee that this will run on every shutdown, it will only | |
# get run on graceful shutdowns such as via a SIGTERM which is what is often | |
# used for zero-downtime deploys | |
@impl GenServer | |
def terminate(_reason, _state) do | |
Logger.info("Shutting down FeltServerWeb.Presence") | |
Phoenix.Tracker.graceful_permdown(MyAppWeb.Presence) | |
:ok | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment