Merge pull request #8371 from HJianBo/auto-retry-auth-resource
AuthN/Z: automaticly re-connect to disconnected resources
This commit is contained in:
commit
c32a416a2a
|
@ -45,9 +45,14 @@
|
|||
?PH_CERT_CN_NAME
|
||||
]).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
-define(DEFAULT_RESOURCE_OPTS, #{
|
||||
auto_retry_interval => 6000,
|
||||
start_after_created => false
|
||||
}).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% APIs
|
||||
%%------------------------------------------------------------------------------
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
create_resource(ResourceId, Module, Config) ->
|
||||
Result = emqx_resource:create_local(
|
||||
|
@ -55,13 +60,14 @@ create_resource(ResourceId, Module, Config) ->
|
|||
?RESOURCE_GROUP,
|
||||
Module,
|
||||
Config,
|
||||
#{start_after_created => false}
|
||||
?DEFAULT_RESOURCE_OPTS
|
||||
),
|
||||
start_resource_if_enabled(Result, ResourceId, Config).
|
||||
|
||||
update_resource(Module, Config, ResourceId) ->
|
||||
Opts = #{start_after_created => false},
|
||||
Result = emqx_resource:recreate_local(ResourceId, Module, Config, Opts),
|
||||
Result = emqx_resource:recreate_local(
|
||||
ResourceId, Module, Config, ?DEFAULT_RESOURCE_OPTS
|
||||
),
|
||||
start_resource_if_enabled(Result, ResourceId, Config).
|
||||
|
||||
start_resource_if_enabled({ok, _} = Result, ResourceId, #{enable := true}) ->
|
||||
|
@ -166,9 +172,9 @@ make_resource_id(Name) ->
|
|||
NameBin = bin(Name),
|
||||
emqx_resource:generate_id(NameBin).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
%%------------------------------------------------------------------------------
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
handle_var({var, Name}, undefined) ->
|
||||
error({cannot_get_variable, Name});
|
||||
|
|
|
@ -34,9 +34,14 @@
|
|||
render_sql_params/2
|
||||
]).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
-define(DEFAULT_RESOURCE_OPTS, #{
|
||||
auto_retry_interval => 6000,
|
||||
start_after_created => false
|
||||
}).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% APIs
|
||||
%%------------------------------------------------------------------------------
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
create_resource(Module, Config) ->
|
||||
ResourceId = make_resource_id(Module),
|
||||
|
@ -48,7 +53,7 @@ create_resource(ResourceId, Module, Config) ->
|
|||
?RESOURCE_GROUP,
|
||||
Module,
|
||||
Config,
|
||||
#{start_after_created => false}
|
||||
?DEFAULT_RESOURCE_OPTS
|
||||
),
|
||||
start_resource_if_enabled(Result, ResourceId, Config).
|
||||
|
||||
|
@ -59,7 +64,7 @@ update_resource(Module, #{annotations := #{id := ResourceId}} = Config) ->
|
|||
ResourceId,
|
||||
Module,
|
||||
Config,
|
||||
#{start_after_created => false}
|
||||
?DEFAULT_RESOURCE_OPTS
|
||||
)
|
||||
of
|
||||
{ok, _} -> {ok, ResourceId};
|
||||
|
@ -125,9 +130,9 @@ render_sql_params(ParamList, Values) ->
|
|||
#{return => rawlist, var_trans => fun handle_sql_var/2}
|
||||
).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
%%------------------------------------------------------------------------------
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
client_vars(ClientInfo) ->
|
||||
maps:from_list(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_resource, [
|
||||
{description, "An OTP application"},
|
||||
{vsn, "0.1.0"},
|
||||
{description, "Manager for all external resources"},
|
||||
{vsn, "0.1.1"},
|
||||
{registered, []},
|
||||
{mod, {emqx_resource_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
%% Unless you know what you are doing, DO NOT edit manually!!
|
||||
{VSN,
|
||||
[{"0.1.0",[{load_module,emqx_resource_manager,brutal_purge,soft_purge,[]}]}
|
||||
],
|
||||
[{"0.1.0",[{load_module,emqx_resource_manager,brutal_purge,soft_purge,[]}]}
|
||||
]}.
|
|
@ -484,7 +484,11 @@ handle_connected_health_check(Data) ->
|
|||
Actions = [{state_timeout, ?HEALTHCHECK_INTERVAL, health_check}],
|
||||
{keep_state, UpdatedData, Actions};
|
||||
(Status, UpdatedData) ->
|
||||
logger:error("health check for ~p failed: ~p", [Data#data.id, Status]),
|
||||
?SLOG(error, #{
|
||||
msg => health_check_failed,
|
||||
id => Data#data.id,
|
||||
status => Status
|
||||
}),
|
||||
{next_state, Status, UpdatedData}
|
||||
end
|
||||
).
|
||||
|
|
Loading…
Reference in New Issue