bolshakov / stoplight

:traffic_light: Traffic control for code.
http://bolshakov.github.io/stoplight/
MIT License
384 stars 40 forks source link

Implement window size #172

Closed bolshakov closed 1 year ago

bolshakov commented 1 year ago

By default, all recorded failures, regardless of the time these happen, will count to reach the threshold (hence turning the light to red). If needed, a window size can be set, meaning you can control how many errors per period of time will count to reach the red state.

 window_size_in_seconds = 2

 light = Stoplight('example-threshold') { 1 / 0 }
   .with_window_size(window_size_in_seconds)
   .with_threshold(1)
 # => #<Stoplight::Light:...>

 light.run
 # #<ZeroDivisionError: divided by 0>
 # => "default"
 sleep(3)
 light.run
 # #<ZeroDivisionError: divided by 0>
 # => "default"

Closes #131 Closes https://github.com/bolshakov/stoplight/pull/133

bolshakov commented 1 year ago

@Lokideos

Jimmeh

bolshakov commented 1 year ago

Good point. I added tests for different Redis versions https://github.com/bolshakov/stoplight/pull/179/files I guess we sorted out how rev option works 😉