Просмотр исходного кода

fix: set resource status disconnected

EMQ-YangM 3 лет назад
Родитель
Сommit
1bf33f75cc

+ 1 - 1
apps/emqx_resource/src/emqx_resource_health_check.erl

@@ -98,7 +98,7 @@ health_check_timeout_checker(Pid, Name, SleepTime, Timeout) ->
             #{name => Name},
             <<Name/binary, " health check timeout">>
         ),
-        emqx_resource:set_resource_status_connecting(Name),
+        _ = emqx_resouce_instance:set_resource_status(Name, disconnected),
         receive
             health_check_finish -> timer:sleep(SleepTime)
         end

+ 27 - 1
apps/emqx_resource/src/emqx_resource_instance.erl

@@ -19,6 +19,7 @@
 
 -include("emqx_resource.hrl").
 -include("emqx_resource_utils.hrl").
+-include_lib("emqx/include/logger.hrl").
 
 -export([start_link/2]).
 
@@ -28,7 +29,8 @@
     get_metrics/1,
     reset_metrics/1,
     list_all/0,
-    list_group/1
+    list_group/1,
+    set_resource_status/2
 ]).
 
 -export([
@@ -339,6 +341,30 @@ do_set_resource_status_connecting(InstId) ->
             {error, Error}
     end.
 
+-spec set_resource_status(instance_id(), resource_connection_status()) -> ok | {error, term()}.
+set_resource_status(InstId, Status) ->
+    case lookup(InstId) of
+        {ok, Group, #{id := _} = Data} ->
+            ?SLOG(
+                error,
+                #{
+                    msg => "health check failed: timeout",
+                    resource_id => InstId
+                }
+            ),
+            update_resource(InstId, Group, Data#{status => Status});
+        Error ->
+            ?SLOG(
+                error,
+                #{
+                    msg => "set resource status field",
+                    resource_id => InstId,
+                    reason => Error
+                }
+            ),
+            Error
+    end.
+
 %%------------------------------------------------------------------------------
 %% internal functions
 %%------------------------------------------------------------------------------