From: Matt Mullins Date: Sat, 4 May 2013 06:56:59 +0000 (-0700) Subject: Bump irc_amqp_listener state version to 3. X-Git-Tag: v9.5~2 X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=d241c9ea655d1aa356ad4cb3e7f07c2cd59c6fdb;p=erlbot.git Bump irc_amqp_listener state version to 3. Convert version 2 state to version 3 by hoping that the listener is only monitoring one process. Thankfully, amqp_bot_listener:listen_for_events creates a monitor so that AMQP will kill IRC. --- diff --git a/irc/irc_amqp_listener.erl b/irc/irc_amqp_listener.erl index da33e92..f615dc3 100644 --- a/irc/irc_amqp_listener.erl +++ b/irc/irc_amqp_listener.erl @@ -2,7 +2,7 @@ %% as PRIVMSG to a particular destination -module(irc_amqp_listener). -behavior(gen_server). --vsn(2). +-vsn(3). -define(EXCHANGE, <<"irc">>). @@ -15,7 +15,8 @@ -export([ init/1, - handle_info/2 + handle_info/2, + code_change/3 ]). -include("irc_util.hrl"). @@ -47,6 +48,17 @@ handle_info( irc_conn:send_command(ConnectionPid, Command), {noreply, State}. +code_change(2, {ConnectionPid}, _) -> + case process_info(self(), monitors) of + {monitors, [{process, ListeningChannel}]} -> + {ok, {ConnectionPid, ListeningChannel}}; + _ -> + {error, cant_find_listening_channel} + end; + +code_change({down, 2}, {ConnectionPid, _ListeningChannel}, _) -> + {ok, {ConnectionPid}}. + %% @doc Sends a message with the given routing key and body to the proper %% exchange send_message(RoutingKey, ReplyTo, Body) ->