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

[couchdb] 02/02: feat: simplify code

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

jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit a8f3ad9d8ca7dc9c12ad22baf188eb76f66e27c3
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Wed Sep 25 11:03:38 2019 +0200

    feat: simplify code
---
 src/couch_stats/src/couch_stats_aggregator.erl | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/couch_stats/src/couch_stats_aggregator.erl b/src/couch_stats/src/couch_stats_aggregator.erl
index f3d2320..0416636 100644
--- a/src/couch_stats/src/couch_stats_aggregator.erl
+++ b/src/couch_stats/src/couch_stats_aggregator.erl
@@ -55,8 +55,8 @@ start_link() ->
 
 init([]) ->
     {ok, Descs} = reload_metrics(),
-    {ok, CT} = erlang:send_after(get_interval(collect), self(), collect),
-    {ok, RT} = erlang:send_after(get_interval(reload), self(), reload),
+    CT = erlang:send_after(get_interval(collect), self(), collect),
+    RT = erlang:send_after(get_interval(reload), self(), reload),
     {ok, #st{descriptions=Descs, stats=[], collect_timer=CT, reload_timer=RT}}.
 
 handle_call(fetch, _from, #st{stats = Stats}=State) ->
@@ -66,7 +66,7 @@ handle_call(flush, _From, State) ->
 handle_call(reload, _from, #st{reload_timer=OldRT} = State) ->
     timer:cancel(OldRT),
     {ok, Descriptions} = reload_metrics(),
-    {ok, RT} = update_timer(reload),
+    RT = update_timer(reload),
     {reply, ok, State#st{descriptions=Descriptions, reload_timer=RT}};
 handle_call(Msg, _From, State) ->
     {stop, {unknown_call, Msg}, error, State}.
@@ -149,15 +149,12 @@ collect(#st{collect_timer=OldCT} = State) ->
         end,
         State#st.descriptions
     ),
-    {ok, CT} = update_timer(collect),
+    CT = update_timer(collect),
     State#st{stats=Stats, collect_timer=CT}.
 
-update_timer(collect) ->
-    Interval = get_interval(collect),
-    erlang:send_after(Interval, self(), collect);
-update_timer(reload) ->
-    Interval = get_interval(reload),
-    erlang:send_after(Interval, self(), reload).
+update_timer(Type) ->
+    Interval = get_interval(Type),
+    erlang:send_after(Interval, self(), Type).
 
 get_interval(reload) -> 1000 * ?RELOAD_INTERVAL;
 get_interval(collect) -> 1000 * config:get_integer("stats", "interval", ?DEFAULT_INTERVAL).