Merge pull request #11700 from lafirest/fix/res_start_timeout
fix(resource): respect the start_timeout
This commit is contained in:
commit
4c810c3e72
|
@ -50,6 +50,10 @@
|
||||||
start_after_created => false
|
start_after_created => false
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-define(DEFAULT_START_OPTS, #{
|
||||||
|
start_timeout => timer:seconds(30)
|
||||||
|
}).
|
||||||
|
|
||||||
-record(?MOD_TAB, {
|
-record(?MOD_TAB, {
|
||||||
backend :: atom(),
|
backend :: atom(),
|
||||||
state :: undefined | map(),
|
state :: undefined | map(),
|
||||||
|
@ -301,7 +305,7 @@ lookup(Backend) ->
|
||||||
%% to avoid resource leakage the resource start will never affect the update result,
|
%% to avoid resource leakage the resource start will never affect the update result,
|
||||||
%% so the resource_id will always be recorded
|
%% so the resource_id will always be recorded
|
||||||
start_resource_if_enabled(ResourceId, {ok, _} = Result, #{enable := true, backend := Backend}) ->
|
start_resource_if_enabled(ResourceId, {ok, _} = Result, #{enable := true, backend := Backend}) ->
|
||||||
case emqx_resource:start(ResourceId) of
|
case emqx_resource:start(ResourceId, ?DEFAULT_START_OPTS) of
|
||||||
ok ->
|
ok ->
|
||||||
ok;
|
ok;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
|
|
@ -223,9 +223,10 @@ restart(ResId, Opts) when is_binary(ResId) ->
|
||||||
%% @doc Start the resource
|
%% @doc Start the resource
|
||||||
-spec start(resource_id(), creation_opts()) -> ok | {error, Reason :: term()}.
|
-spec start(resource_id(), creation_opts()) -> ok | {error, Reason :: term()}.
|
||||||
start(ResId, Opts) ->
|
start(ResId, Opts) ->
|
||||||
case safe_call(ResId, start, ?T_OPERATION) of
|
StartTimeout = maps:get(start_timeout, Opts, ?T_OPERATION),
|
||||||
|
case safe_call(ResId, start, StartTimeout) of
|
||||||
ok ->
|
ok ->
|
||||||
wait_for_ready(ResId, maps:get(start_timeout, Opts, 5000));
|
wait_for_ready(ResId, StartTimeout);
|
||||||
{error, _Reason} = Error ->
|
{error, _Reason} = Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue