Class: Seekmodo::Sdk::SignatureMismatchTracker
- Inherits:
-
Object
- Object
- Seekmodo::Sdk::SignatureMismatchTracker
- Defined in:
- lib/seekmodo/sdk/signature_mismatch_tracker.rb
Constant Summary collapse
- CACHE_KEY =
"numinix.seekmodo.sigmismatch_failures"- DEFAULT_WINDOW_SECONDS =
300- DEFAULT_THRESHOLD =
3
Instance Method Summary collapse
- #clear ⇒ Object
- #failures_in_window ⇒ Object
-
#initialize(cache, window_seconds: DEFAULT_WINDOW_SECONDS, threshold: DEFAULT_THRESHOLD, clock: nil) ⇒ SignatureMismatchTracker
constructor
A new instance of SignatureMismatchTracker.
- #record_failure ⇒ Object
- #tripped? ⇒ Boolean
Constructor Details
#initialize(cache, window_seconds: DEFAULT_WINDOW_SECONDS, threshold: DEFAULT_THRESHOLD, clock: nil) ⇒ SignatureMismatchTracker
Returns a new instance of SignatureMismatchTracker.
12 13 14 15 16 17 |
# File 'lib/seekmodo/sdk/signature_mismatch_tracker.rb', line 12 def initialize(cache, window_seconds: DEFAULT_WINDOW_SECONDS, threshold: DEFAULT_THRESHOLD, clock: nil) @cache = cache @window_seconds = window_seconds @threshold = threshold @clock = clock || -> { Time.now.to_i } end |
Instance Method Details
#clear ⇒ Object
26 27 28 |
# File 'lib/seekmodo/sdk/signature_mismatch_tracker.rb', line 26 def clear @cache.delete(CACHE_KEY) end |
#failures_in_window ⇒ Object
34 35 36 |
# File 'lib/seekmodo/sdk/signature_mismatch_tracker.rb', line 34 def failures_in_window load_and_prune(@clock.call).length end |
#record_failure ⇒ Object
19 20 21 22 23 24 |
# File 'lib/seekmodo/sdk/signature_mismatch_tracker.rb', line 19 def record_failure now = @clock.call rows = load_and_prune(now) rows << now @cache.set(CACHE_KEY, rows, [@window_seconds * 2, 60].max) end |
#tripped? ⇒ Boolean
30 31 32 |
# File 'lib/seekmodo/sdk/signature_mismatch_tracker.rb', line 30 def tripped? load_and_prune(@clock.call).length >= @threshold end |