Преглед на файлове

fix: always return ok when remove local resource

zhongwencool преди 2 години
родител
ревизия
c26a18e949
променени са 2 файла, в които са добавени 18 реда и са изтрити 3 реда
  1. 17 2
      apps/emqx_resource/src/emqx_resource.erl
  2. 1 1
      apps/emqx_resource/test/emqx_resource_SUITE.erl

+ 17 - 2
apps/emqx_resource/src/emqx_resource.erl

@@ -19,6 +19,7 @@
 -include("emqx_resource.hrl").
 -include("emqx_resource_utils.hrl").
 -include("emqx_resource_errors.hrl").
+-include_lib("emqx/include/logger.hrl").
 
 %% APIs for resource types
 
@@ -257,9 +258,23 @@ recreate_local(ResId, ResourceType, Config, Opts) ->
 remove(ResId) ->
     emqx_resource_proto_v1:remove(ResId).
 
--spec remove_local(resource_id()) -> ok | {error, Reason :: term()}.
+-spec remove_local(resource_id()) -> ok.
 remove_local(ResId) ->
-    emqx_resource_manager:remove(ResId).
+    case emqx_resource_manager:remove(ResId) of
+        ok ->
+            ok;
+        {error, not_found} ->
+            ok;
+        Error ->
+            %% Only log, the ResId worker is always remove in manager's remove action.
+            ?SLOG(warning, #{
+                msg => "remove_local_resource_failed",
+                error => Error,
+                resource_id => ResId
+            }),
+            ok
+    end,
+    ok.
 
 -spec reset_metrics_local(resource_id()) -> ok.
 reset_metrics_local(ResId) ->

+ 1 - 1
apps/emqx_resource/test/emqx_resource_SUITE.erl

@@ -164,7 +164,7 @@ t_create_remove_local(_) ->
             ),
 
             ?assertEqual(ok, emqx_resource:remove_local(?ID)),
-            ?assertMatch({error, _}, emqx_resource:remove_local(?ID)),
+            ?assertMatch(ok, emqx_resource:remove_local(?ID)),
 
             ?assertMatch(
                 ?RESOURCE_ERROR(not_found),