Class: Findbug::Alerts::Dispatcher
- Inherits:
-
Object
- Object
- Findbug::Alerts::Dispatcher
- Defined in:
- lib/findbug/alerts/dispatcher.rb
Overview
Dispatcher routes alerts to configured channels.
ALERT FLOW
-
Error captured → PersistJob runs
-
PersistJob calls Dispatcher.notify(error_event)
-
Dispatcher checks throttling (avoid spam)
-
Dispatcher sends to enabled channels (async via AlertJob)
CHANNEL SOURCE
Alert channels are stored in the database (findbug_alert_channels table) and managed via the dashboard UI at /findbug/alerts.
THROTTLING
If your app throws 1000 errors in a minute, you don’t want 1000 Slack messages. Throttling limits alerts to one per error fingerprint per throttle period (default 5 minutes).
CHANNEL PRIORITY
Different channels for different severities:
-
Critical errors → All channels (email, Slack, etc.)
-
Warnings → Maybe just Slack
-
Info → Maybe just logged, no alerts
Class Method Summary collapse
-
.any_enabled? ⇒ Boolean
Check if any alert channels are enabled in the database.
-
.notify(error_event, async: true) ⇒ Object
Send alert for an error event.
-
.send_alerts(error_event) ⇒ Object
Actually send alerts to all enabled channels.
Class Method Details
.any_enabled? ⇒ Boolean
Check if any alert channels are enabled in the database
74 75 76 77 78 |
# File 'lib/findbug/alerts/dispatcher.rb', line 74 def any_enabled? Findbug::AlertChannel.enabled.exists? rescue StandardError false end |
.notify(error_event, async: true) ⇒ Object
Send alert for an error event
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/findbug/alerts/dispatcher.rb', line 43 def notify(error_event, async: true) return unless Findbug.enabled? return unless any_enabled? return unless should_alert?(error_event) return if throttled?(error_event) if async Jobs::AlertJob.perform_later(error_event.id) else send_alerts(error_event) end record_alert(error_event) end |
.send_alerts(error_event) ⇒ Object
Actually send alerts to all enabled channels
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/findbug/alerts/dispatcher.rb', line 62 def send_alerts(error_event) Findbug::AlertChannel.enabled.find_each do |channel_record| channel_instance = channel_record.channel_class.new(channel_record.config.symbolize_keys) channel_instance.send_alert(error_event) rescue StandardError => e Findbug.logger.error( "[Findbug] Failed to send alert to #{channel_record.name}: #{e.}" ) end end |