This commit is contained in:
anlicheng 2025-04-07 15:54:51 +08:00
parent abbd6e2f70
commit 03ba9ced25
4 changed files with 33 additions and 14 deletions

View File

@ -13,8 +13,9 @@ start(_StartType, _StartArgs) ->
io:setopts([{encoding, unicode}]), io:setopts([{encoding, unicode}]),
%% %%
erlang:system_flag(fullsweep_after, 16), erlang:system_flag(fullsweep_after, 16),
%% mnesia
start_mnesia(), ok = mnesia:start(),
%% http服务
start_http_server(), start_http_server(),
dimension_apn_sup:start_link(). dimension_apn_sup:start_link().
@ -47,13 +48,4 @@ start_http_server() ->
{ok, Pid} = cowboy:start_clear(http_listener, TransOpts, #{env => #{dispatch => Dispatcher}}), {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]). 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.

View File

@ -30,7 +30,7 @@
%%%=================================================================== %%%===================================================================
test() -> test() ->
UserId = <<"">>, UserId = <<"ed1021b3-d88c-4016-aaf2-340793b16ebf">>,
Title = <<"动物狂响曲"/utf8>>, Title = <<"动物狂响曲"/utf8>>,
Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>, Body = <<"第7集(校服与被毛更深处),bilibili已更新"/utf8>>,
push([ push([

View 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.

View File

@ -25,7 +25,7 @@ create_table() ->
-spec insert(UserId :: binary(), DeviceToken :: binary(), Timestamp :: integer()) -> ok | {error, Reason :: any()}. -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) -> insert(UserId, DeviceToken, Timestamp) when is_binary(UserId), is_binary(DeviceToken), is_integer(Timestamp) ->
Record = #device_token{user_id = UserId, token = DeviceToken, timestamp = 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} -> {'atomic', Res} ->
Res; Res;
{'aborted', Reason} -> {'aborted', Reason} ->