@@ -125,8 +125,16 @@ handle_config_terminate(_, stop, _) ->
125125handle_config_terminate (_Server , _Reason , _State ) ->
126126 erlang :send_after (? RELISTEN_DELAY , whereis (? MODULE ), restart_config_listener ).
127127
128+ get_snooze_period () ->
129+ % The snooze_period_ms option should be used, but snooze_period is supported
130+ % for legacy reasons.
131+ Default = config :get_integer (" compaction_daemon" , " snooze_period" , 3 ),
132+ case config :get_integer (" compaction_daemon" , " snooze_period_ms" , - 1 ) of
133+ - 1 -> Default * 1000 ;
134+ SnoozePeriod -> SnoozePeriod
135+ end .
136+
128137compact_loop (Parent ) ->
129- SnoozePeriod = config :get_integer (" compaction_daemon" , " snooze_period" , 3 ),
130138 {ok , _ } = couch_server :all_databases (
131139 fun (DbName , Acc ) ->
132140 case ets :info (? CONFIG_ETS , size ) =:= 0 of
@@ -140,7 +148,7 @@ compact_loop(Parent) ->
140148 case check_period (Config ) of
141149 true ->
142150 maybe_compact_db (Parent , DbName , Config ),
143- ok = timer :sleep (SnoozePeriod * 1000 );
151+ ok = timer :sleep (get_snooze_period () );
144152 false ->
145153 ok
146154 end
@@ -231,8 +239,7 @@ maybe_compact_views(DbName, [DDocName | Rest], Config) ->
231239 timeout ->
232240 ok
233241 end ,
234- SnoozePeriod = config :get_integer (" compaction_daemon" , " snooze_period" , 3 ),
235- ok = timer :sleep (SnoozePeriod * 1000 );
242+ ok = timer :sleep (get_snooze_period ());
236243 false ->
237244 ok
238245 end .
@@ -597,4 +604,60 @@ abs_path2_test() ->
597604 ? assertEqual ({ok , " /a/b/" }, abs_path2 (" /a/b" )),
598605 ok .
599606
607+ get_snooze_period_test_ () ->
608+ {
609+ foreach ,
610+ fun () ->
611+ meck :new (config , [passthrough ])
612+ end ,
613+ fun (_ ) ->
614+ meck :unload ()
615+ end ,
616+ [
617+ {" should return default value without config attributes" ,
618+ fun should_default_without_config /0 },
619+ {" should respect old config attribute" ,
620+ fun should_respect_old_config /0 },
621+ {" should respect old config set to zero" ,
622+ fun should_respect_old_config_zero /0 },
623+ {" should respect new config attribute" ,
624+ fun should_respect_new_config /0 },
625+ {" should respect new config set to zero" ,
626+ fun should_respect_new_config_zero /0 }
627+ ]
628+ }.
629+
630+ should_default_without_config () ->
631+ ? assertEqual (3000 , get_snooze_period ()).
632+
633+ should_respect_old_config () ->
634+ meck :expect (config , get_integer , fun
635+ (" compaction_daemon" , " snooze_period" , _ ) -> 1 ;
636+ (_ , _ , Default ) -> Default
637+ end ),
638+ ? assertEqual (1000 , get_snooze_period ()).
639+
640+ should_respect_old_config_zero () ->
641+ meck :expect (config , get_integer , fun
642+ (" compaction_daemon" , " snooze_period" , _ ) -> 0 ;
643+ (_ , _ , Default ) -> Default
644+ end ),
645+ ? assertEqual (0 , get_snooze_period ()).
646+
647+ should_respect_new_config () ->
648+ meck :expect (config , get_integer , fun
649+ (" compaction_daemon" , " snooze_period" , _ ) -> 1 ;
650+ (" compaction_daemon" , " snooze_period_ms" , _ ) -> 300 ;
651+ (_ , _ , Default ) -> Default
652+ end ),
653+ ? assertEqual (300 , get_snooze_period ()).
654+
655+ should_respect_new_config_zero () ->
656+ meck :expect (config , get_integer , fun
657+ (" compaction_daemon" , " snooze_period" , _ ) -> 1 ;
658+ (" compaction_daemon" , " snooze_period_ms" , _ ) -> 0 ;
659+ (_ , _ , Default ) -> Default
660+ end ),
661+ ? assertEqual (0 , get_snooze_period ()).
662+
600663- endif .
0 commit comments