Merge pull request #8852 from zhongwencool/return-503-when-router-not-ready
fix: return 503 if dashboard's routers not ready
This commit is contained in:
commit
b54ebacd3e
|
@ -2,7 +2,7 @@
|
||||||
{application, emqx_dashboard, [
|
{application, emqx_dashboard, [
|
||||||
{description, "EMQX Web Dashboard"},
|
{description, "EMQX Web Dashboard"},
|
||||||
% strict semver, bump manually!
|
% strict semver, bump manually!
|
||||||
{vsn, "5.0.4"},
|
{vsn, "5.0.5"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_dashboard_sup]},
|
{registered, [emqx_dashboard_sup]},
|
||||||
{applications, [kernel, stdlib, mnesia, minirest, emqx]},
|
{applications, [kernel, stdlib, mnesia, minirest, emqx]},
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
execute(Req, Env) ->
|
execute(Req, Env) ->
|
||||||
case check_dispatch_ready(Env) of
|
case check_dispatch_ready(Env) of
|
||||||
true -> add_cors_flag(Req, Env);
|
true -> add_cors_flag(Req, Env);
|
||||||
false -> {stop, cowboy_req:reply(503, Req)}
|
false -> {stop, cowboy_req:reply(503, #{<<"retry-after">> => <<"15">>}, Req)}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
add_cors_flag(Req, Env) ->
|
add_cors_flag(Req, Env) ->
|
||||||
|
|
|
@ -33,18 +33,26 @@ init(Req0, State) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
running_status() ->
|
running_status() ->
|
||||||
BrokerStatus =
|
case emqx_dashboard_listener:is_ready(timer:seconds(20)) of
|
||||||
case emqx:is_running() of
|
true ->
|
||||||
true ->
|
BrokerStatus = broker_status(),
|
||||||
started;
|
AppStatus = application_status(),
|
||||||
false ->
|
Body = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), BrokerStatus, AppStatus]),
|
||||||
stopped
|
{200, #{<<"content-type">> => <<"text/plain">>}, list_to_binary(Body)};
|
||||||
end,
|
false ->
|
||||||
AppStatus =
|
{503, #{<<"retry-after">> => <<"15">>}, <<>>}
|
||||||
case lists:keysearch(emqx, 1, application:which_applications()) of
|
end.
|
||||||
false -> not_running;
|
|
||||||
{value, _Val} -> running
|
broker_status() ->
|
||||||
end,
|
case emqx:is_running() of
|
||||||
Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), BrokerStatus, AppStatus]),
|
true ->
|
||||||
Body = list_to_binary(Status),
|
started;
|
||||||
{200, #{<<"content-type">> => <<"text/plain">>}, Body}.
|
false ->
|
||||||
|
stopped
|
||||||
|
end.
|
||||||
|
|
||||||
|
application_status() ->
|
||||||
|
case lists:keysearch(emqx, 1, application:which_applications()) of
|
||||||
|
false -> not_running;
|
||||||
|
{value, _Val} -> running
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue