删除通道前,先禁用

This commit is contained in:
Evan You 2022-06-02 17:59:34 +08:00
parent d066a1c2d8
commit 538841cf68

View File

@ -115,6 +115,7 @@ init(?TYPE, ChannelId, Args) ->
dgiot_parse_hook:subscribe(<<"Product">>, post, ChannelId),
dgiot_parse_hook:subscribe(<<"Product/*">>, put, ChannelId),
dgiot_parse_hook:subscribe(<<"Product/*">>, delete, ChannelId),
dgiot_parse_hook:subscribe(<<"Channel/*">>, delete, ChannelId),
{ok, State, []}.
handle_init(State) ->
@ -209,6 +210,15 @@ handle_message({sync_parse, _Pid, 'after', delete, _Token, <<"Product">>, Object
dgiot_product:delete(ObjectId),
{ok, State};
handle_message({sync_parse, _Pid, 'before', delete, _Token, <<"Channel">>, ObjectId}, State) ->
io:format("~s ~p ~p ~n", [?FILE, ?LINE, ObjectId]),
case dgiot_parse:get_object(<<"Channel">>, ObjectId) of
{ok, #{<<"isEnable">> := true}} ->
dgiot_bridge:control_channel(ObjectId, <<"disable">>);
_ -> pass
end,
{ok, State};
handle_message({update_schemas_json}, State) ->
%%
dgiot_parse:update_schemas_json(),