Class: RailsErrorDashboard::Commands::FlushSwallowedExceptions

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

Overview

Command: Upsert swallowed exception raise/rescue counts into the database.

Receives snapshot hashes from SwallowedExceptionTracker and merges them into hourly-bucketed rows. Uses find_or_initialize_by + increment for cross-database compatibility (no raw SQL upsert).

raise_counts keys: “ClassName|path:line” rescue_counts keys: “ClassName|raise_path:line->rescue_path:line”

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raise_counts:, rescue_counts:) ⇒ FlushSwallowedExceptions

Returns a new instance of FlushSwallowedExceptions.



18
19
20
21
# File 'lib/rails_error_dashboard/commands/flush_swallowed_exceptions.rb', line 18

def initialize(raise_counts:, rescue_counts:)
  @raise_counts = raise_counts
  @rescue_counts = rescue_counts
end

Class Method Details

.call(raise_counts:, rescue_counts:) ⇒ Object



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

def self.call(raise_counts:, rescue_counts:)
  new(raise_counts: raise_counts, rescue_counts: rescue_counts).call
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rails_error_dashboard/commands/flush_swallowed_exceptions.rb', line 23

def call
  period = Time.current.beginning_of_hour
  app_id = current_application_id

  # Process raise counts
  @raise_counts.each do |key, count|
    class_name, location = key.split("|", 2)
    next if class_name.blank? || location.blank?

    upsert_raise(class_name, location, period, app_id, count)
  end

  # Process rescue counts
  @rescue_counts.each do |key, count|
    class_name, locations = key.split("|", 2)
    next if class_name.blank? || locations.blank?

    raise_loc, rescue_loc = locations.split("->", 2)
    next if raise_loc.blank?

    upsert_rescue(class_name, raise_loc, rescue_loc, period, app_id, count)
  end
rescue => e
  RailsErrorDashboard::Logger.debug(
    "[RailsErrorDashboard] FlushSwallowedExceptions failed: #{e.class} - #{e.message}"
  )
end