2 Star 10 Fork 5

lora/lorawan-server

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
lorawan_connector_monitor.erl 1.68 KB
Copy Edit Raw Blame History
%
% Copyright (c) 2016-2019 Petr Gotthard <petr.gotthard@centrum.cz>
% All rights reserved.
% Distributed under the terms of the MIT License. See the LICENSE file.
%
-module(lorawan_connector_monitor).
-behaviour(gen_server).
-export([start_link/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-include("lorawan_db.hrl").
-record(state, {period}).
% Default connector health check period 10 seconds
-define(DEFAULT_PERIOD, 10000).
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
init([]) ->
Period = application:get_env(lorawan_server, connector_monitor_period,
?DEFAULT_PERIOD),
{ok, #state{period=Period}, Period}.
handle_call(_Request, _From, State) ->
{stop, {error, unknownmsg}, State}.
handle_cast(_Msg, #state{period=Period}=State) ->
{noreply, State, Period}.
handle_info(timeout, #state{period=Period}=State) ->
% run through known connectors, attempt restart if failed with 'network'
lists:foreach(
fun(ConnId) ->
[Connector] = mnesia:dirty_read(connector, ConnId),
restart_connector(Connector)
end,
mnesia:dirty_all_keys(connector)),
{noreply, State, Period};
handle_info(Info, #state{period=Period}=State) ->
lager:debug("unknown info ~p", [Info]),
{noreply, State, Period}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
restart_connector(#connector{enabled=true, failed=[<<"network">>]}=Connector) ->
{atomic, ok} = mnesia:transaction(
fun() ->
lorawan_admin:write(Connector#connector{failed=[]})
end);
restart_connector(_Connector) ->
ok.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Erlang
1
https://gitee.com/mlora/lorawan-server.git
git@gitee.com:mlora/lorawan-server.git
mlora
lorawan-server
lorawan-server
master

Search