Class: RailsErrorDashboard::Commands::UpsertBaseline

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

Overview

Command: Create or update an error baseline record

Handles the persistence of baseline statistics calculated by Services::BaselineCalculator. The calculator handles querying and pure statistics; this command handles all writes.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_type:, platform:, baseline_type:, period_start:, period_end:, stats:, count:, sample_size:) ⇒ UpsertBaseline

Returns a new instance of UpsertBaseline.



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

def initialize(error_type:, platform:, baseline_type:, period_start:, period_end:, stats:, count:, sample_size:)
  @error_type = error_type
  @platform = platform
  @baseline_type = baseline_type
  @period_start = period_start
  @period_end = period_end
  @stats = stats
  @count = count
  @sample_size = sample_size
end

Class Method Details

.call(error_type:, platform:, baseline_type:, period_start:, period_end:, stats:, count:, sample_size:) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/rails_error_dashboard/commands/upsert_baseline.rb', line 11

def self.call(error_type:, platform:, baseline_type:, period_start:, period_end:, stats:, count:, sample_size:)
  new(
    error_type: error_type, platform: platform, baseline_type: baseline_type,
    period_start: period_start, period_end: period_end,
    stats: stats, count: count, sample_size: sample_size
  ).call
end

Instance Method Details

#callObject



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/upsert_baseline.rb', line 30

def call
  baseline = ErrorBaseline.find_or_initialize_by(
    error_type: @error_type,
    platform: @platform,
    baseline_type: @baseline_type,
    period_start: @period_start
  )

  baseline.update!(
    period_end: @period_end,
    count: @count,
    mean: @stats[:mean],
    std_dev: @stats[:std_dev],
    percentile_95: @stats[:percentile_95],
    percentile_99: @stats[:percentile_99],
    sample_size: @sample_size
  )

  baseline
end