-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverse the logic from pull to push. (#210)
- Loading branch information
Showing
7 changed files
with
62 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
defmodule Amqpx.SignalHandler do | ||
@moduledoc """ | ||
Signal handler behaviour is used to catch the SIGTERM signal and gracefully stop the application. | ||
In the context of Rabbitmq, it will: | ||
cancel the channel when we are in draining mode to stop prefetch new messages. | ||
close the channel when we are in stopping mode to reject all the unacked messages that we did't start to consume. | ||
This module is responsible for handling signals sent to the application. | ||
""" | ||
use GenServer | ||
|
||
Check in Peano how to use it. | ||
def start_link do | ||
GenServer.start_link(__MODULE__, [], name: __MODULE__) | ||
end | ||
|
||
""" | ||
@doc """ | ||
Check if the application is in draining mode. | ||
""" | ||
@callback draining? :: boolean | ||
def init(_) do | ||
{:ok, :running} | ||
end | ||
|
||
@doc """ | ||
Check if the application is in stopping mode. | ||
""" | ||
@callback stopping? :: boolean | ||
def draining do | ||
GenServer.call(__MODULE__, :draining) | ||
end | ||
|
||
def stopping do | ||
GenServer.call(__MODULE__, :stopping) | ||
end | ||
|
||
def get_signal_status do | ||
GenServer.call(__MODULE__, :get_signal_status) | ||
end | ||
|
||
def handle_call(:draining, _from, _state) do | ||
{:reply, :ok, :draining} | ||
end | ||
|
||
def handle_call(:stopping, _from, _state) do | ||
{:reply, :ok, :stopping} | ||
end | ||
|
||
def handle_call(:get_signal_status, _from, state) do | ||
{:reply, state, state} | ||
end | ||
end |
This file contains 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
This file contains 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