Class: QueuePulse::Notifiers::Slack
- Defined in:
- lib/queue_pulse/notifiers/slack.rb
Overview
Posts alerts to a Slack Incoming Webhook. Payload building is separated from delivery so it can be unit-tested without the network.
Constant Summary
Constants inherited from Base
Base::MAX_RETRIES, Base::OPEN_TIMEOUT, Base::READ_TIMEOUT
Instance Method Summary collapse
- #deliver(alerts) ⇒ Object
-
#initialize(webhook_url:) ⇒ Slack
constructor
A new instance of Slack.
-
#payload(alerts) ⇒ Hash
The Slack message body for these alerts.
Constructor Details
#initialize(webhook_url:) ⇒ Slack
Returns a new instance of Slack.
8 9 10 11 |
# File 'lib/queue_pulse/notifiers/slack.rb', line 8 def initialize(webhook_url:) super() @webhook_url = webhook_url end |
Instance Method Details
#deliver(alerts) ⇒ Object
13 14 15 16 17 |
# File 'lib/queue_pulse/notifiers/slack.rb', line 13 def deliver(alerts) return if alerts.empty? post_json(@webhook_url, payload(alerts)) end |
#payload(alerts) ⇒ Hash
Returns the Slack message body for these alerts.
20 21 22 |
# File 'lib/queue_pulse/notifiers/slack.rb', line 20 def payload(alerts) { blocks: alerts.flat_map { |alert| blocks_for(alert) } } end |