Class: Chantier::FailurePolicies::WithinInterval
- Defined in:
- lib/failure_policies.rb
Overview
Limits the number of failures that may be registered within the given interval
policy = Count.new(10)
policy_within_interval = FailWithinTimePeriod.new(policy, 60 * 2) # 2 minutes
policy_within_interval.limit_reached? # => false
#... and then during 1 minute
5.times { policy_within_interval.failure! }
policy_within_interval.limit_reached? # => true
Once the interval is passed, the error count will be reset back to 0.
Instance Method Summary collapse
- #arm! ⇒ Object
- #failure! ⇒ Object
-
#initialize(policy, interval_in_seconds) ⇒ WithinInterval
constructor
A new instance of WithinInterval.
- #limit_reached? ⇒ Boolean
- #success! ⇒ Object
Constructor Details
#initialize(policy, interval_in_seconds) ⇒ WithinInterval
Returns a new instance of WithinInterval.
107 108 109 110 |
# File 'lib/failure_policies.rb', line 107 def initialize(policy, interval_in_seconds) @policy = policy @interval = interval_in_seconds end |
Instance Method Details
#arm! ⇒ Object
117 118 119 120 121 |
# File 'lib/failure_policies.rb', line 117 def arm! @policy.arm! @interval_started = Time.now.utc.to_f @count = 0 end |
#failure! ⇒ Object
123 124 125 126 |
# File 'lib/failure_policies.rb', line 123 def failure! interval_cutoff! @policy.failure! end |
#limit_reached? ⇒ Boolean
128 129 130 |
# File 'lib/failure_policies.rb', line 128 def limit_reached? @policy.limit_reached? end |
#success! ⇒ Object
112 113 114 115 |
# File 'lib/failure_policies.rb', line 112 def success! interval_cutoff! @policy.success! end |