diff --git a/apps/iot/src/iot_app.erl b/apps/iot/src/iot_app.erl index 07414f3..a99c2d2 100644 --- a/apps/iot/src/iot_app.erl +++ b/apps/iot/src/iot_app.erl @@ -13,6 +13,9 @@ start(_StartType, _StartArgs) -> io:setopts([{encoding, unicode}]), %% 启动数据库 mnesia:start(), + Tables = mnesia:system_info(tables), + iot_util:assert_exec(lists:member(router, [Tables]), fun() -> mnesia:wait_for_tables([router], infinity) end), + %% 加速内存的回收 erlang:system_flag(fullsweep_after, 16), diff --git a/apps/iot/src/iot_util.erl b/apps/iot/src/iot_util.erl index ec01914..ecd9b0e 100644 --- a/apps/iot/src/iot_util.erl +++ b/apps/iot/src/iot_util.erl @@ -13,7 +13,7 @@ -export([timestamp/0, number_format/2, current_time/0]). -export([step/3, chunks/2, rand_bytes/1, uuid/0]). -export([json_data/1, json_error/2]). --export([queue_limited_in/3]). +-export([queue_limited_in/3, assert_exec/2]). %% 时间,精确到毫秒 timestamp() -> @@ -80,4 +80,10 @@ queue_limited_in(Item, Q, Num) when is_integer(Num) -> queue:in(Item, Q1); false -> queue:in(Item, Q) - end. \ No newline at end of file + end. + +-spec assert_exec(boolean(), any()) -> any(). +assert_exec(true, Fun) when is_function(Fun, 0) -> + {ok, Fun()}; +assert_exec(_, _) -> + aborted. \ No newline at end of file