-export([
init/1,
handle_info/2,
- code_change/3
+ code_change/3,
+ terminate/2
]).
-include("irc_util.hrl").
gen_server:start_link(?MODULE, {ConnectionPid, RoutingKey}, []).
init({ConnectionPid, RoutingKey}) ->
+ process_flag(trap_exit, true),
{ok, _, ListeningChannel} = amqp_bot_listener:listen_for_events(RoutingKey),
{ok, {ConnectionPid, ListeningChannel}}.
code_change({down, 2}, {ConnectionPid, _ListeningChannel}, _) ->
{ok, {ConnectionPid}}.
+terminate(Reason, {ConnectionPid, ListeningChannel}) ->
+ error_logger:warning_msg("Tearing down channel ~p for reason ~p", [ListeningChannel, Reason]),
+ amqp_channel:close(ListeningChannel).
+
%% @doc Sends a message with the given routing key and body to the proper
%% exchange
send_message(RoutingKey, ReplyTo, Body) ->
Child = {"amqp_" ++ RoutingKey,
{irc_amqp_listener, start_link, [ConnectionPid, RoutingKey]},
transient,
- brutal_kill,
+ 200,
worker,
[irc_amqp_listener]
},