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") ⇒ Object

Parameters:

  • started_at (String)

    ISO8601 episode start

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

    breaker state at notification time (“shedding”/“open”)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/jobs/rails_error_dashboard/storm_notification_job.rb', line 14

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

  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