Class: Bugstack::Deduplicator
- Inherits:
-
Object
- Object
- Bugstack::Deduplicator
- Defined in:
- lib/bugstack/fingerprint.rb
Overview
Client-side error deduplicator. Prevents the same error (by fingerprint) from being reported more than once within a configurable time window.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(window: 300.0) ⇒ Deduplicator
constructor
A new instance of Deduplicator.
-
#should_send?(fingerprint) ⇒ Boolean
Check if an error should be sent.
Constructor Details
#initialize(window: 300.0) ⇒ Deduplicator
Returns a new instance of Deduplicator.
62 63 64 65 66 |
# File 'lib/bugstack/fingerprint.rb', line 62 def initialize(window: 300.0) @cache = {} @window = window @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ Object
87 88 89 |
# File 'lib/bugstack/fingerprint.rb', line 87 def clear @mutex.synchronize { @cache.clear } end |
#should_send?(fingerprint) ⇒ Boolean
Check if an error should be sent. Thread-safe.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bugstack/fingerprint.rb', line 72 def should_send?(fingerprint) now = Process.clock_gettime(Process::CLOCK_MONOTONIC) @mutex.synchronize do last_sent = @cache[fingerprint] if last_sent && (now - last_sent) < @window return false end @cache[fingerprint] = now cleanup(now) true end end |