Skip to content

Commit ba99ec7

Browse files
committed
Merge remote branch 'cloudant:3102-fix-config_subscription'
This closes #4 Signed-off-by: ILYA Khlopotov <iilyak@ca.ibm.com>
2 parents c7c75eb + 126a849 commit ba99ec7

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/ioq.erl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
% config_listener api
2121
-export([handle_config_change/5, handle_config_terminate/3]).
2222

23+
-define(RELISTEN_DELAY, 5000).
24+
2325
-record(state, {
2426
concurrency,
2527
ratio,
@@ -83,6 +85,9 @@ handle_info({'DOWN', Ref, _, _, Reason}, State) ->
8385
false ->
8486
{noreply, State, 0}
8587
end;
88+
handle_info(restart_config_listener, State) ->
89+
ok = config:listen_for_changes(?MODULE, nil),
90+
{noreply, State};
8691
handle_info(timeout, State) ->
8792
{noreply, maybe_submit_request(State)}.
8893

@@ -91,13 +96,10 @@ handle_config_change("ioq", _, _, _, _) ->
9196
handle_config_change(_, _, _, _, _) ->
9297
{ok, nil}.
9398

94-
handle_config_terminate(_, stop, _) -> ok;
95-
handle_config_terminate(_, _, _) ->
96-
spawn(fun() ->
97-
timer:sleep(5000),
98-
config:listen_for_changes(?MODULE, nil)
99-
end),
100-
ok.
99+
handle_config_terminate(_Server, stop, _State) ->
100+
ok;
101+
handle_config_terminate(_Server, _Reason, _State) ->
102+
erlang:send_after(?RELISTEN_DELAY, whereis(?MODULE), restart_config_listener).
101103

102104
code_change(_Vsn, State, _Extra) ->
103105
{ok, State}.

src/ioq_sup.erl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-module(ioq_sup).
1414
-behaviour(supervisor).
1515
-export([start_link/0, init/1]).
16+
-export([handle_config_change/5, handle_config_terminate/3]).
1617

1718
%% Helper macro for declaring children of supervisor
1819
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
@@ -21,4 +22,24 @@ start_link() ->
2122
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
2223

2324
init([]) ->
24-
{ok, { {one_for_one, 5, 10}, [?CHILD(ioq, worker)]}}.
25+
{ok, { {one_for_one, 5, 10}, [
26+
{
27+
config_listener_mon,
28+
{config_listener_mon, start_link, [?MODULE, nil]},
29+
permanent,
30+
5000,
31+
worker,
32+
[config_listener_mon]
33+
},
34+
?CHILD(ioq, worker)
35+
]} }.
36+
37+
handle_config_change("ioq", _Key, _Val, _Persist, St) ->
38+
gen_server:cast(ioq_server, update_config),
39+
{ok, St};
40+
handle_config_change(_Sec, _Key, _Val, _Persist, St) ->
41+
{ok, St}.
42+
43+
handle_config_terminate(_Server, _Reason, _State) ->
44+
gen_server:cast(ioq_server, update_config),
45+
ok.

0 commit comments

Comments
 (0)