Class: RailsErrorDashboard::BaselineAlertJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/rails_error_dashboard/baseline_alert_job.rb

Overview

Sends baseline anomaly alerts through configured notification channels

This job is triggered when an error exceeds baseline thresholds. It respects cooldown periods to prevent alert fatigue and sends notifications through all enabled channels (Slack, Email, Discord, etc.)

Instance Method Summary collapse

Instance Method Details

#perform(error_log_id, anomaly_data, locale = nil) ⇒ Object

Parameters:

  • error_log_id (Integer)

    The error log that triggered the alert

  • anomaly_data (Hash)

    Anomaly information from baseline check

  • locale (String, nil) (defaults to: nil)

    resolved at enqueue time. nil for jobs enqueued by a pre-Phase-4 version still draining from the queue.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/jobs/rails_error_dashboard/baseline_alert_job.rb', line 16

def perform(error_log_id, anomaly_data, locale = nil)
  error_log = ErrorLog.find_by(id: error_log_id)
  return unless error_log

  config = RailsErrorDashboard.configuration

  # Check if we should send alert (cooldown check)
  unless Services::BaselineAlertThrottler.should_alert?(
    error_log.error_type,
    error_log.platform,
    cooldown_minutes: config.baseline_alert_cooldown_minutes
  )
    Rails.logger.info(
      "Baseline alert throttled for #{error_log.error_type} on #{error_log.platform}"
    )
    return
  end

  # Record that we're sending an alert
  Services::BaselineAlertThrottler.record_alert(
    error_log.error_type,
    error_log.platform
  )

  # Send notifications through all enabled channels
  send_notifications(error_log, anomaly_data, config, job_locale(locale))
end