Class: Epilog::Rails::ActiveJobSubscriber

Inherits:
LogSubscriber
  • Object
show all
Defined in:
lib/epilog/rails/active_job_subscriber.rb

Instance Attribute Summary

Attributes inherited from LogSubscriber

#logger

Instance Method Summary collapse

Methods inherited from LogSubscriber

#config, #initialize, #pop_context, #push_context

Constructor Details

This class inherits a constructor from Epilog::Rails::LogSubscriber

Instance Method Details

#enqueue(event) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/epilog/rails/active_job_subscriber.rb', line 6

def enqueue(event)
  ex = event.payload[:exception_object]

  if ex
    error do
      event_hash('Failed enqueuing job', event)
    end
  elsif event.payload[:aborted]
    info do
      event_hash(
        'Failed enqueuing job, a before_enqueue callback ' \
          'halted the enqueuing execution.',
        event
      )
    end
  else
    info { event_hash('Enqueued job', event) }
  end
end

#enqueue_at(event) ⇒ Object



26
27
28
# File 'lib/epilog/rails/active_job_subscriber.rb', line 26

def enqueue_at(event)
  enqueue(event)
end

#perform(event) ⇒ Object

rubocop:disable Metrics/MethodLength



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/epilog/rails/active_job_subscriber.rb', line 38

def perform(event)
  ex = event.payload[:exception_object]
  if ex
    error do
      event_hash('Error performing job', event).merge(
        metrics: {
          job_runtime: event.duration
        }
      )
    end
  elsif event.payload[:aborted]
    error do
      event_hash(
        'Error performing job, a before_perform ' \
          'callback halted the job execution',
        event
      ).merge(
        metrics: {
          job_runtime: event.duration
        }
      )
    end
  else
    info do
      event_hash('Performed job', event).merge(
        metrics: {
          job_runtime: event.duration
        }
      )
    end
  end

  pop_context
end

#perform_start(event) ⇒ Object



30
31
32
33
34
35
# File 'lib/epilog/rails/active_job_subscriber.rb', line 30

def perform_start(event)
  push_context(job: short_job_hash(event.payload[:job]))
  return unless config.double_job_logs

  info { event_hash('Performing job', event) }
end