class SlackAlert
Minimal Slack webhook. No-op (with a logger) when no webhook is configured.
Public Class Methods
# File app/services/slack_alert.rb, line 19 def initialize(message, webhook: nil, channel: nil) @message = message @webhook = webhook @channel = channel end
Creates the alert with a message and optional webhook override.
@param message [String] the alert text @param webhook [String, nil] the webhook URL to post to @param channel [String, nil] an optional #channel override in the payload
# File app/services/slack_alert.rb, line 10 def self.notify(message, webhook: nil, channel: nil) new(message, webhook: webhook, channel: channel).call end
Convenience entry point that sends a message to a webhook.
@param message [String] the alert text @param webhook [String, nil] the webhook URL to post to @param channel [String, nil] an optional #channel override in the payload
Public Instance Methods
Source
# File app/services/slack_alert.rb, line 31 def call url = @webhook.presence || ENV["SLACK_WEBHOOK_URL"] unless url Rails.logger.info("SlackAlert skipped (no webhook configured): #{@message}") return end post(url) rescue StandardError => e Rails.logger.warn("Failed to send Slack alert: #{e.message}") raise end
Posts the alert, skipping with a log when no webhook is configured.
A failed send RAISES so the caller can distinguish a delivered alert from a rejected one — swallowing the error here made AlertNotifier report the send as successful, stamp last_alert_at, and then permanently suppress further alerts for the table while the webhook was dead.