Skip to content

Commit

Permalink
Upgrade the plugin for EMQ X R3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emqplus committed Aug 27, 2018
1 parent c68f534 commit d08115f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -3,13 +3,13 @@ PROJECT_DESCRIPTION = EMQ X Recon Plugin
PROJECT_VERSION = 3.0

DEPS = recon
dep_recon = git https://github.com/ferd/recon 2.3.5
dep_recon = git https://github.com/ferd/recon 2.3.6

BUILD_DEPS = emqx
dep_emqx = git git@github.com:emqtt/emqttd emqx30
dep_emqx = git https://github.com:emqtt/emqttd emqx30

TEST_DEPS = emqx_ct_helpers
dep_emqx_ct_helpers = git git@github.com:emqx/emqx-ct-helpers
dep_emqx_ct_helpers = git https://github.com:emqx/emqx-ct-helpers

NO_AUTOPATCH = cuttlefish

Expand Down
2 changes: 1 addition & 1 deletion rebar.config
@@ -1,4 +1,4 @@
{deps, [
{recon,".*",{git,"https://github.com/ferd/recon","2.3.4"}}
{recon,".*",{git,"https://github.com/ferd/recon","2.3.6"}}
]}.
{erl_opts, [debug_info,warnings_as_errors,warn_export_all,warn_unused_import,{parse_transform,lager_transform}]}.
2 changes: 1 addition & 1 deletion src/emqx_recon_cli.erl
Expand Up @@ -47,7 +47,7 @@ cmd(_) ->
{"recon remote_load Mod", "recon:remote_load(Mod)"}]).

unload() ->
emqx_cli:unregister_command(recon).
emqx_ctl:unregister_command(recon).

concat(Key, Keyword) ->
lists:concat([atom_to_list(Key), "/", atom_to_list(Keyword)]).
Expand Down
23 changes: 11 additions & 12 deletions src/emqx_recon_gc.erl
Expand Up @@ -16,20 +16,19 @@

-behaviour(gen_server).

-export([start_link/0, run/0]).
-export([start_link/0]).
-export([run/0]).

%% gen_server
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).

-record(state, {timer}).

%% 5 minutes
-define(DEFAULT_INTERVAL, 300000).

-spec(start_link() -> {ok, pid()}).
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

run() ->
gen_server:call(?MODULE, run, infinity).
Expand All @@ -39,38 +38,38 @@ run() ->
%%--------------------------------------------------------------------

init([]) ->
{ok, schedule_gc(#state{})}.
{ok, schedule_gc(#{timer => undefined})}.

handle_call(run, _From, State) ->
{Time, _} = timer:tc(fun run_gc/0),
{reply, {ok, Time}, State, hibernate};

handle_call(_Req, _From, State) ->
{reply, ignored, State}.
{reply, ignored, State}.

handle_cast(_Msg, State) ->
{noreply, State}.
{noreply, State}.

handle_info(run, State) ->
run_gc(),
{noreply, schedule_gc(State), hibernate};
{noreply, schedule_gc(State), hibernate};

handle_info(_Info, State) ->
{noreply, State}.
{noreply, State}.

terminate(_Reason, _State) ->
ok.
ok.

code_change(_OldVsn, State, _Extra) ->
{ok, State}.
{ok, State}.

%%--------------------------------------------------------------------
%% Internel function
%%--------------------------------------------------------------------

schedule_gc(State) ->
Interval = application:get_env(emqx_recon, gc_interval, ?DEFAULT_INTERVAL),
State#state{timer = erlang:send_after(Interval, self(), run)}.
State#{timer := erlang:send_after(Interval, self(), run)}.

run_gc() ->
[garbage_collect(P) || P <- processes(),
Expand Down
10 changes: 7 additions & 3 deletions src/emqx_recon_sup.erl
Expand Up @@ -20,11 +20,15 @@

-export([init/1]).

-define(CHILD(I), {I, {I, start_link, []}, permanent, 5000, worker, [I]}).

start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).

init([]) ->
{ok, {{one_for_one, 10, 100}, [?CHILD(emqx_recon_gc)]}}.
{ok, {{one_for_one, 10, 100},
[#{id => recon_gc,
start => {emqx_recon_gc, start_link, []},
restart => permanent,
shutdown => 5000,
type => worker,
modules => [emqx_recon_gc]}]}}.

0 comments on commit d08115f

Please sign in to comment.