You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2019/09/11 15:50:13 UTC

[couchdb-smoosh] 01/02: Fix check_window responses

This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a commit to branch scheduled-smoosh
in repository https://gitbox.apache.org/repos/asf/couchdb-smoosh.git

commit c6c074237f43856c6dac7d482e2e1c128d785549
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Fri Sep 6 14:24:03 2019 -0400

    Fix check_window responses
---
 src/smoosh_channel.erl | 10 +++++-----
 src/smoosh_utils.erl   |  9 +++++----
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/smoosh_channel.erl b/src/smoosh_channel.erl
index a6269fc..d8a8d14 100644
--- a/src/smoosh_channel.erl
+++ b/src/smoosh_channel.erl
@@ -156,18 +156,18 @@ handle_info(check_window, State0) ->
     {ok, State} = code_change(nil, State0, nil),
     #state{paused = Paused, name = Name} = State,
     StrictWindow = smoosh_utils:get(Name, "strict_window", "false"),
-    FinalState = case {Paused, smoosh_utils:check_window(Name)} of
-        {true, pause} ->
+    FinalState = case {not Paused, smoosh_utils:in_allowed_window(Name)} of
+        {false, false} ->
             % already in desired state
             State;
-        {false, resume} ->
+        {true, true} ->
             % already in desired state
             State;
-        {true, resume} ->
+        {false, true} ->
             % resume is always safe even if we did not previously suspend
             {reply, ok, NewState} = handle_call(resume, nil, State),
             NewState;
-        {false, pause} ->
+        {true, false} ->
             if StrictWindow =:= "true" ->
                 {reply, ok, NewState} = handle_call(suspend, nil, State),
                 NewState;
diff --git a/src/smoosh_utils.erl b/src/smoosh_utils.erl
index 32c90db..b433de0 100644
--- a/src/smoosh_utils.erl
+++ b/src/smoosh_utils.erl
@@ -15,7 +15,7 @@
 
 -export([get/2, get/3, group_pid/1, split/1, stringify/1, ignore_db/1]).
 -export([
-    check_window/1
+    in_allowed_window/1
 ]).
 
 group_pid({Shard, GroupId}) ->
@@ -60,12 +60,12 @@ ignore_db(DbName) when is_list(DbName) ->
 ignore_db(Db) ->
     ignore_db(couch_db:name(Db)).
 
-check_window(Channel) ->
+in_allowed_window(Channel) ->
     From = parse_time(get(Channel, "from"), {00, 00}),
     To = parse_time(get(Channel, "to"), {24, 00}),
-    check_window(From, To).
+    in_allowed_window(From, To).
 
-check_window(From, To) ->
+in_allowed_window(From, To) ->
     {HH, MM, _} = erlang:time(),
     case From < To of
     true ->
@@ -74,6 +74,7 @@ check_window(From, To) ->
         ({HH, MM} >= From) orelse ({HH, MM} < To)
     end.
 
+
 parse_time(undefined, Default) ->
     Default;
 parse_time(String, Default) ->