Class: Stackify::ErrorsGovernor
- Defined in:
- lib/stackify/errors_governor.rb
Instance Method Summary collapse
- #can_send?(ex) ⇒ Boolean
-
#initialize(purge_period = 5) ⇒ ErrorsGovernor
constructor
A new instance of ErrorsGovernor.
Constructor Details
#initialize(purge_period = 5) ⇒ ErrorsGovernor
Returns a new instance of ErrorsGovernor.
6 7 8 9 10 11 |
# File 'lib/stackify/errors_governor.rb', line 6 def initialize purge_period=5 @history = {} @@history_lock = Mutex.new @purge_period = purge_period update_purge_times end |
Instance Method Details
#can_send?(ex) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stackify/errors_governor.rb', line 13 def can_send? ex key = unique_key_of(ex) @@history_lock.synchronize do epoch_minute = current_minute init_history_key_if_not_exists key, epoch_minute history_entry = @history[key] if history_entry[:epoch_minute] == epoch_minute history_entry[:count] += 1 answer = history_entry[:count] <= Stackify.configuration.flood_limit else @history[key]={ epoch_minute: epoch_minute, count: 1 } answer = true end clear_old_history_entries if time_for_purge_is_come? answer end end |