Class: RailsErrorDashboard::Commands::IncrementCascadeDetection
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Commands::IncrementCascadeDetection
- Defined in:
- lib/rails_error_dashboard/commands/increment_cascade_detection.rb
Overview
Command: Update a cascade pattern’s stats when a new detection occurs This is a write operation that increments frequency, recalculates average delay, and updates last_detected_at timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(pattern, delay_seconds) ⇒ IncrementCascadeDetection
constructor
A new instance of IncrementCascadeDetection.
Constructor Details
#initialize(pattern, delay_seconds) ⇒ IncrementCascadeDetection
Returns a new instance of IncrementCascadeDetection.
13 14 15 16 |
# File 'lib/rails_error_dashboard/commands/increment_cascade_detection.rb', line 13 def initialize(pattern, delay_seconds) @pattern = pattern @delay_seconds = delay_seconds end |
Class Method Details
.call(pattern, delay_seconds) ⇒ Object
9 10 11 |
# File 'lib/rails_error_dashboard/commands/increment_cascade_detection.rb', line 9 def self.call(pattern, delay_seconds) new(pattern, delay_seconds).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_error_dashboard/commands/increment_cascade_detection.rb', line 18 def call @pattern.frequency += 1 # Update average delay using incremental formula if @pattern.avg_delay_seconds.present? @pattern.avg_delay_seconds = ((@pattern.avg_delay_seconds * (@pattern.frequency - 1)) + @delay_seconds) / @pattern.frequency else @pattern.avg_delay_seconds = @delay_seconds end @pattern.last_detected_at = Time.current @pattern.save @pattern end |