fix
This commit is contained in:
parent
abbd6e2f70
commit
03ba9ced25
@ -13,8 +13,9 @@ start(_StartType, _StartArgs) ->
|
||||
io:setopts([{encoding, unicode}]),
|
||||
%% 加速内存的回收
|
||||
erlang:system_flag(fullsweep_after, 16),
|
||||
|
||||
start_mnesia(),
|
||||
%% 启动mnesia
|
||||
ok = mnesia:start(),
|
||||
%% 启动http服务
|
||||
start_http_server(),
|
||||
dimension_apn_sup:start_link().
|
||||
|
||||
@ -47,13 +48,4 @@ start_http_server() ->
|
||||
|
||||
{ok, Pid} = cowboy:start_clear(http_listener, TransOpts, #{env => #{dispatch => Dispatcher}}),
|
||||
|
||||
lager:debug("[dimension_apn] the http server start at: ~p, pid is: ~p", [Port, Pid]).
|
||||
|
||||
%% 启动内存数据库
|
||||
start_mnesia() ->
|
||||
%% 启动数据库
|
||||
ok = mnesia:start(),
|
||||
Tables = mnesia:system_info(tables),
|
||||
%% 创建数据库表
|
||||
not lists:member(device_token, Tables) andalso mnesia_device_token:create_table(),
|
||||
ok.
|
||||
lager:debug("[dimension_apn] the http server start at: ~p, pid is: ~p", [Port, Pid]).
|
||||
@ -30,7 +30,7 @@
|
||||
%%%===================================================================
|
||||
|
||||
test() ->
|
||||
UserId = <<"">>,
|
||||
UserId = <<"ed1021b3-d88c-4016-aaf2-340793b16ebf">>,
|
||||
Title = <<"动物狂响曲"/utf8>>,
|
||||
Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>,
|
||||
push([
|
||||
|
||||
27
apps/dimension_apn/src/dimension_mnesia_manager.erl
Normal file
27
apps/dimension_apn/src/dimension_mnesia_manager.erl
Normal file
@ -0,0 +1,27 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author anlicheng
|
||||
%%% @copyright (C) 2025, <COMPANY>
|
||||
%%% @doc
|
||||
%%%
|
||||
%%% @end
|
||||
%%% Created : 07. 4月 2025 15:47
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(dimension_mnesia_manager).
|
||||
-author("anlicheng").
|
||||
|
||||
%% API
|
||||
-export([init_database/0]).
|
||||
|
||||
%% 只能调用一次
|
||||
init_database() ->
|
||||
%% 清理掉以前的schema
|
||||
mnesia:stop(),
|
||||
mnesia:delete_schema([node()]),
|
||||
|
||||
%% 创建schema
|
||||
ok = mnesia:create_schema([node()]),
|
||||
ok = mnesia:start(),
|
||||
%% 创建数据库表
|
||||
mnesia_device_token:create_table(),
|
||||
|
||||
ok.
|
||||
@ -25,7 +25,7 @@ create_table() ->
|
||||
-spec insert(UserId :: binary(), DeviceToken :: binary(), Timestamp :: integer()) -> ok | {error, Reason :: any()}.
|
||||
insert(UserId, DeviceToken, Timestamp) when is_binary(UserId), is_binary(DeviceToken), is_integer(Timestamp) ->
|
||||
Record = #device_token{user_id = UserId, token = DeviceToken, timestamp = Timestamp},
|
||||
case mnesia:transaction(mnesia:write(device_token, Record, write)) of
|
||||
case mnesia:transaction(fun() -> mnesia:write(device_token, Record, write) end) of
|
||||
{'atomic', Res} ->
|
||||
Res;
|
||||
{'aborted', Reason} ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user