Class: QueuePulse::Notifiers::Email
- Defined in:
- lib/queue_pulse/notifiers/email.rb
Overview
Sends a plain-text digest email via ActionMailer. Body building is separated for testing. Requires ActionMailer to be configured in the host app (Requirements US-6.4).
Constant Summary
Constants inherited from Base
Base::MAX_RETRIES, Base::OPEN_TIMEOUT, Base::READ_TIMEOUT
Instance Method Summary collapse
- #body(alerts) ⇒ Object
- #deliver(alerts) ⇒ Object
-
#initialize(to:, from: "queue_pulse@localhost", subject_prefix: "[QueuePulse]") ⇒ Email
constructor
A new instance of Email.
- #subject(alerts) ⇒ Object
Constructor Details
#initialize(to:, from: "queue_pulse@localhost", subject_prefix: "[QueuePulse]") ⇒ Email
Returns a new instance of Email.
9 10 11 12 13 14 |
# File 'lib/queue_pulse/notifiers/email.rb', line 9 def initialize(to:, from: "queue_pulse@localhost", subject_prefix: "[QueuePulse]") super() @to = to @from = from @subject_prefix = subject_prefix end |
Instance Method Details
#body(alerts) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/queue_pulse/notifiers/email.rb', line 41 def body(alerts) alerts.map do |alert| lines = ["#{alert.emoji} #{alert.title}", alert.] alert.context.each { |k, v| lines << " #{k}: #{v}" } lines.join("\n") end.join("\n\n") end |
#deliver(alerts) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/queue_pulse/notifiers/email.rb', line 16 def deliver(alerts) return if alerts.empty? unless defined?(ActionMailer::Base) logger.warn("[QueuePulse] Email notifier requires ActionMailer; skipping #{alerts.size} alert(s)") return end mail = ActionMailer::Base.mail( to: @to, from: @from, subject: subject(alerts), body: body(alerts) ) mail.deliver_now end |
#subject(alerts) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/queue_pulse/notifiers/email.rb', line 33 def subject(alerts) if alerts.size == 1 "#{@subject_prefix} #{alerts.first.title}" else "#{@subject_prefix} #{alerts.size} alerts" end end |