irc_conn: migrate state from vsn 4 to 5 and back
authorMatt Mullins <mmullins@mmlx.us>
Tue, 15 Apr 2014 06:26:28 +0000 (23:26 -0700)
committerMatt Mullins <mmullins@mmlx.us>
Tue, 15 Apr 2014 07:11:39 +0000 (00:11 -0700)
This adds a "none" timer id on upgrade, and removes the timer id on downgrade.

irc/irc_conn.erl

index b09214a..e28123e 100644 (file)
@@ -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}.