Class: RailsErrorDashboard::StormNotificationJob

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

Overview

Sends the SINGLE "error storm in progress" notification per storm episode.

During a storm, per-error notifications are suppressed (500 Slack pings help nobody) — this one message replaces them. The gate guarantees at most one enqueue per episode; this job just delivers.

Instance Method Summary collapse

Instance Method Details

#perform(started_at:, state: "shedding", locale: nil) ⇒ Object

Parameters:

  • started_at (String)

    ISO8601 episode start

  • state (String) (defaults to: "shedding")

    breaker state at notification time ("shedding"/"open")

  • 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
# File 'app/jobs/rails_error_dashboard/storm_notification_job.rb', line 16

def perform(started_at:, state: "shedding", locale: nil)
  config = RailsErrorDashboard.configuration
  message = build_message(started_at, state, config, job_locale(locale))

  if config.enable_slack_notifications && config.slack_webhook_url.present?
    post_json(config.slack_webhook_url, { text: message })
  end

  if config.enable_discord_notifications && config.discord_webhook_url.present?
    post_json(config.discord_webhook_url, { content: message })
  end

  if config.enable_webhook_notifications && config.webhook_urls.any?
    payload = {
      event: "error_storm_detected",
      started_at: started_at,
      state: state,
      application: app_name(config)
    }
    config.webhook_urls.each { |url| post_json(url, payload) }
  end
rescue => e
  Rails.logger.error("[RailsErrorDashboard] StormNotificationJob failed: #{e.class} - #{e.message}")
end