Improve the 'open_session/3' API

This commit is contained in:
Feng Lee 2019-09-18 19:48:55 +08:00
parent 94c324d7a3
commit a313d1c722
1 changed files with 4 additions and 4 deletions

View File

@ -161,15 +161,15 @@ set_chan_stats(ClientId, ChanPid, Stats) ->
present := boolean(), present := boolean(),
pendings => list()}} pendings => list()}}
| {error, Reason :: term()}). | {error, Reason :: term()}).
open_session(true, Client = #{client_id := ClientId}, Options) -> open_session(true, ClientInfo = #{client_id := ClientId}, ConnInfo) ->
CleanStart = fun(_) -> CleanStart = fun(_) ->
ok = discard_session(ClientId), ok = discard_session(ClientId),
Session = emqx_session:init(Client, Options), Session = emqx_session:init(ClientInfo, ConnInfo),
{ok, #{session => Session, present => false}} {ok, #{session => Session, present => false}}
end, end,
emqx_cm_locker:trans(ClientId, CleanStart); emqx_cm_locker:trans(ClientId, CleanStart);
open_session(false, Client = #{client_id := ClientId}, Options) -> open_session(false, ClientInfo = #{client_id := ClientId}, ConnInfo) ->
ResumeStart = fun(_) -> ResumeStart = fun(_) ->
case takeover_session(ClientId) of case takeover_session(ClientId) of
{ok, ConnMod, ChanPid, Session} -> {ok, ConnMod, ChanPid, Session} ->
@ -179,7 +179,7 @@ open_session(false, Client = #{client_id := ClientId}, Options) ->
present => true, present => true,
pendings => Pendings}}; pendings => Pendings}};
{error, not_found} -> {error, not_found} ->
Session = emqx_session:init(Client, Options), Session = emqx_session:init(ClientInfo, ConnInfo),
{ok, #{session => Session, present => false}} {ok, #{session => Session, present => false}}
end end
end, end,