Class: RailsInformant::NotifyJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/rails_informant/notify_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(group) ⇒ Object



13
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_informant/notify_job.rb', line 13

def perform(group)
  Current.delivering_notification = true

  occurrence = group.occurrences.order(created_at: :desc).first
  failures = []

  notifiers.each do |notifier|
    next unless notifier.should_notify?(group)

    notifier.notify(group, occurrence)
  rescue StandardError => e
    failures << e
  end

  if failures.empty?
    group.update_column(:last_notified_at, Time.current)
    Notifiers::CircuitBreaker.record_success
  else
    Notifiers::CircuitBreaker.record_failure
    failures.drop(1).each { |e| Rails.logger.error "[RailsInformant] Notifier failed: #{e.class}: #{e.message}" }
    raise failures.first
  end
ensure
  Current.delivering_notification = false
end