Class: RailsErrorDashboard::Commands::FindOrIncrementError

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/commands/find_or_increment_error.rb

Overview

Command: Find an existing error by hash or create a new one Uses pessimistic locking to prevent race conditions in multi-app scenarios. If an unresolved error with the same hash exists within 24 hours, increments its occurrence count. Otherwise creates a new error record.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_hash, attributes = {}) ⇒ FindOrIncrementError

Returns a new instance of FindOrIncrementError.



14
15
16
17
# File 'lib/rails_error_dashboard/commands/find_or_increment_error.rb', line 14

def initialize(error_hash, attributes = {})
  @error_hash = error_hash
  @attributes = attributes
end

Class Method Details

.call(error_hash, attributes = {}) ⇒ Object



10
11
12
# File 'lib/rails_error_dashboard/commands/find_or_increment_error.rb', line 10

def self.call(error_hash, attributes = {})
  new(error_hash, attributes).call
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
# File 'lib/rails_error_dashboard/commands/find_or_increment_error.rb', line 19

def call
  existing = find_existing

  if existing
    increment_existing(existing)
  else
    create_new_or_retry
  end
end