couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject couch-log commit: updated refs/heads/master to 2f70cc8
Date Wed, 10 Aug 2016 22:08:32 GMT
Repository: couchdb-couch-log
Updated Branches:
  refs/heads/master c73efdc2a -> 2f70cc8dd


Really actually fix test for the config listener

Of course now that the handler is tied to the process that calls
listen_for_changes this test was racing the anonymous process that was
starting the handler.

This just turns couch_log_config_listener into a simple gen_server that
sits in couch_log's supervision tree that handles restarting the
listener.

COUCHDB-3069


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/2f70cc8d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/2f70cc8d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/2f70cc8d

Branch: refs/heads/master
Commit: 2f70cc8ddb1a6a8d512aa53490138d9c2754eb07
Parents: c73efdc
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Wed Aug 10 17:07:05 2016 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Aug 10 17:07:05 2016 -0500

----------------------------------------------------------------------
 src/couch_log_config_listener.erl | 50 +++++++++++++++++++++++++++++-----
 src/couch_log_sup.erl             |  9 +++++-
 2 files changed, 51 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/2f70cc8d/src/couch_log_config_listener.erl
----------------------------------------------------------------------
diff --git a/src/couch_log_config_listener.erl b/src/couch_log_config_listener.erl
index 287f79d..bb51e63 100644
--- a/src/couch_log_config_listener.erl
+++ b/src/couch_log_config_listener.erl
@@ -11,11 +11,21 @@
 % the License.
 
 -module(couch_log_config_listener).
+-behaviour(gen_server).
 -behaviour(config_listener).
 
 
 -export([
-    start/0
+    start_link/0
+]).
+
+-export([
+    init/1,
+    terminate/2,
+    handle_call/3,
+    handle_cast/2,
+    handle_info/2,
+    code_change/3
 ]).
 
 -export([
@@ -31,8 +41,37 @@
 -endif.
 
 
-start() ->
-    ok = config:listen_for_changes(?MODULE, nil).
+start_link() ->
+    gen_server:start_link({local, ?MODULE}, ?MODULE, nil, []).
+
+
+init(_) ->
+    ok = config:listen_for_changes(?MODULE, nil),
+    {ok, nil}.
+
+
+terminate(_, _) ->
+    ok.
+
+
+handle_call(_, _, _) ->
+    {reply, ignored, nil}.
+
+
+handle_cast(_, _) ->
+    {noreply, nil}.
+
+
+handle_info(restart_listener, _) ->
+    ok = config:listen_for_changes(?MODULE, nil),
+    {noreply, nil};
+
+handle_info(_, _) ->
+    {noreply, nil}.
+
+
+code_change(_, _, _) ->
+    {ok, nil}.
 
 
 handle_config_change("log", Key, _, _, _) ->
@@ -56,10 +95,7 @@ handle_config_change(_, _, _, _, Settings) ->
 handle_config_terminate(_, stop, _) ->
     ok;
 handle_config_terminate(_, _, _) ->
-    spawn(fun() ->
-        timer:sleep(?RELISTEN_DELAY),
-        ok = config:listen_for_changes(?MODULE, nil)
-    end).
+    erlang:send_after(?RELISTEN_DELAY, whereis(?MODULE), restart_listener).
 
 
 -ifdef(TEST).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/2f70cc8d/src/couch_log_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_log_sup.erl b/src/couch_log_sup.erl
index 3106659..fc84a8a 100644
--- a/src/couch_log_sup.erl
+++ b/src/couch_log_sup.erl
@@ -24,7 +24,6 @@ start_link() ->
 
 init([]) ->
     ok = couch_log_config:init(),
-    ok = couch_log_config_listener:start(),
     {ok, {{one_for_one, 1, 1}, children()}}.
 
 
@@ -45,5 +44,13 @@ children() ->
             5000,
             worker,
             [couch_log_monitor]
+        },
+        {
+            couch_log_config_listener,
+            {couch_log_config_listener, start_link, []},
+            permanent,
+            5000,
+            worker,
+            [couch_log_config_listener]
         }
     ].


Mime
View raw message