Class: TgErrorNotifier::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/tg_error_notifier/subscriber.rb

Class Method Summary collapse

Class Method Details

.attach!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tg_error_notifier/subscriber.rb', line 5

def self.attach!
  return if @attached

  ActiveSupport::Notifications.subscribe("perform.active_job") do |_name, _start, _finish, _id, payload|
    exception = payload[:exception_object]
    next unless exception

    job = payload[:job]
    TgErrorNotifier.notify(
      exception: exception,
      source: "active_job",
      context: {
        job_class: job&.class&.name,
        job_id: job&.job_id,
        queue: job&.queue_name,
        executions: job&.executions
      }
    )
  end

  @attached = true
end