Skip to content

Commit

Permalink
Add clarifying comments and be explicit about signal states
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnabell committed Nov 28, 2024
1 parent 432e932 commit 8462514
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/amqp/gen/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,24 @@ defmodule Amqpx.Gen.Consumer do
@spec handle_signals(signal_status(), state(), String.t()) :: {:ok | :stop, state()}
defp handle_signals(signal_status \\ get_signal_status(), state, consumer_tag)

# Close channel when we we need to stop.
defp handle_signals(:stopping, state, _) do
close_channel(state.channel)
{:stop, state}
end

defp handle_signals(_, %{cancelled?: true} = state, _), do: {:ok, state}
# Continue processing prefetched messages while draining
defp handle_signals(:draining, %{cancelled?: true} = state, _), do: {:ok, state}

# Stop consuming new messages and move to cancelled state to continue processing prefetched messages

Check warning on line 278 in lib/amqp/gen/consumer.ex

View workflow job for this annotation

GitHub Actions / ci

Line is too long (max is 98, was 102).
defp handle_signals(:draining, state, consumer_tag) do
Logger.info("Cancelling consumer #{consumer_tag}")
Basic.cancel(state.channel, consumer_tag)
{:ok, %{state | cancelled?: true}}
end

defp handle_signals(_, state, _), do: {:ok, state}
# No signals received run as normal
defp handle_signals(:running, state, _), do: {:ok, state}

defp signal_handler, do: Application.get_env(:amqpx, :signal_handler, Amqpx.NoSignalHandler)
end

0 comments on commit 8462514

Please sign in to comment.