diff --git a/apps/endpoint/src/endpoint_buffer.erl b/apps/endpoint/src/endpoint_buffer.erl index 1a7b3a1..3ccc24b 100644 --- a/apps/endpoint/src/endpoint_buffer.erl +++ b/apps/endpoint/src/endpoint_buffer.erl @@ -18,12 +18,12 @@ -export_type([buffer/0]). -record(buffer, { - endpoint, + endpoint :: #endpoint{}, next_id = 1 :: integer(), %% 当前数据所在的游标 cursor = 0 :: integer(), %% ets存储的引用 - tid :: reference(), + tid :: ets:tid(), %% 定时器 timer_pid :: pid(), %% 窗口大小,允许最大的未确认消息数 @@ -49,7 +49,7 @@ new(Endpoint = #endpoint{id = Id}, WindowSize) when is_integer(WindowSize), Wind EtsName = list_to_atom("endpoint_buffer_ets:" ++ integer_to_list(Id)), Tid = ets:new(EtsName, [ordered_set, private]), %% 定义重发器 - TimerPid = endpoint_timer:start_link(?RETRY_INTERVAL), + {ok, TimerPid} = endpoint_timer:start_link(?RETRY_INTERVAL), #buffer{cursor = 0, tid = Tid, timer_pid = TimerPid, endpoint = Endpoint, window_size = WindowSize}. diff --git a/apps/endpoint/src/endpoint_http.erl b/apps/endpoint/src/endpoint_http.erl index c71740c..8da36da 100644 --- a/apps/endpoint/src/endpoint_http.erl +++ b/apps/endpoint/src/endpoint_http.erl @@ -30,7 +30,7 @@ %%%=================================================================== %% @doc Spawns the server and registers the local name (unique) --spec(start_link(Name :: atom(), Endpoint :: #http_endpoint{}) -> +-spec(start_link(Name :: atom(), Endpoint :: #endpoint{}) -> {ok, Pid :: pid()} | ignore | {error, Reason :: term()}). start_link(Name, Endpoint = #endpoint{config = #http_endpoint{}}) when is_atom(Name) -> gen_server:start_link({local, Name}, ?MODULE, [Endpoint], []). @@ -82,7 +82,7 @@ handle_cast(cleanup, State = #state{buffer = Buffer}) -> {noreply, NewState :: #state{}} | {noreply, NewState :: #state{}, timeout() | hibernate} | {stop, Reason :: term(), NewState :: #state{}}). -handle_info({next_data, Id, _LocationCode, Body}, State = #state{buffer = Buffer, endpoint = #http_endpoint{url = Url}}) -> +handle_info({next_data, Id, _LocationCode, Body}, State = #state{buffer = Buffer, endpoint = #endpoint{config = #http_endpoint{url = Url}}}) -> Headers = [ {<<"content-type">>, <<"application/json">>} ], @@ -91,7 +91,7 @@ handle_info({next_data, Id, _LocationCode, Body}, State = #state{buffer = Buffer {ok, RespBody} = hackney:body(ClientRef), hackney:close(ClientRef), lager:debug("[http_postman] url: ~p, response is: ~p", [Url, RespBody]), - NBuffer = endpoint_buffer:ack(Buffer, Id), + NBuffer = endpoint_buffer:ack(Id, Buffer), {noreply, State#state{buffer = NBuffer}}; {ok, HttpCode, _, ClientRef} -> diff --git a/apps/endpoint/src/endpoint_sup.erl b/apps/endpoint/src/endpoint_sup.erl index 09df645..2bf517e 100644 --- a/apps/endpoint/src/endpoint_sup.erl +++ b/apps/endpoint/src/endpoint_sup.erl @@ -9,7 +9,7 @@ -include("endpoint.hrl"). -export([start_link/0]). --export([ensured_endpoint_started/1, delete_endpoint/1, stat/0]). +-export([ensured_endpoint_started/1, delete_endpoint/1]). -export([init/1]). @@ -45,13 +45,6 @@ ensured_endpoint_started(Endpoint = #endpoint{}) -> {error, Error} end. -stat() -> - Children = supervisor:which_children(?MODULE), - lists:foreach(fun({Id, Pid, _, _}) -> - Stat = catch endpoint:get_stat(Pid), - lager:debug("[iot_endpoint] id: ~p, stat: ~p", [Id, Stat]) - end, Children). - delete_endpoint(Id) when is_integer(Id) -> Name = endpoint:get_name(Id), supervisor:terminate_child(?MODULE, Name),