From: Matt Mullins Date: Tue, 15 Apr 2014 06:26:28 +0000 (-0700) Subject: irc_conn: migrate state from vsn 4 to 5 and back X-Git-Tag: v11~3 X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=0b0db397170c91beca135d62c9c4944812a16357;p=erlbot.git irc_conn: migrate state from vsn 4 to 5 and back This adds a "none" timer id on upgrade, and removes the timer id on downgrade. --- diff --git a/irc/irc_conn.erl b/irc/irc_conn.erl index b09214a..e28123e 100644 --- a/irc/irc_conn.erl +++ b/irc/irc_conn.erl @@ -202,30 +202,13 @@ reset_ping_timer(#irc_state{ping_timer = Timer} = State) -> terminate(_Reason, _State) -> ok. -code_change(3, State, ok) -> - RoutingKey = get_routing_key(State#irc_state.instance), - AmqpListener = irc_object_sup:get_amqp_listener( - State#irc_state.object_sup, - RoutingKey), - case AmqpListener of - {error, notfound} -> ok; - Pid -> irc_amqp_listener:stop(Pid) - end, - irc_object_sup:delete_amqp_listener( - State#irc_state.object_sup, - RoutingKey), - gen_server:cast(self(), create_object_sup), - {ok, State}; +code_change(4, OldState, ok) -> + NewState = list_to_tuple(tuple_to_list(OldState) ++ [none]), + error_logger:info_msg("Updating irc state from ~p to ~p~n", [OldState, NewState]), + {ok, NewState}; -code_change({down, 3}, State, ok) -> - RoutingKey = get_routing_key(State#irc_state.instance), - % Downgrade doesn't need to ask the irc_amqp_listener to stop gracefully, - % since the childspec actually allows it to terminate itself cleanly. - irc_object_sup:delete_amqp_listener( - State#irc_state.object_sup, - RoutingKey), - gen_server:cast(self(), create_object_sup), - {ok, State}; +code_change({down, 4}, State, ok) -> + {ok, list_to_tuple(lists:sublist(tuple_to_list(State), 9))}; code_change(_OldVsn, _State, _Extra) -> {error, unsupported}.