Class: ActiveJob::LogSubscriber

Inherits:
ActiveSupport::EventReporter::LogSubscriber show all
Defined in:
activejob/lib/active_job/log_subscriber.rb

Overview

:nodoc:

Constant Summary

Constants inherited from ActiveSupport::EventReporter::LogSubscriber

ActiveSupport::EventReporter::LogSubscriber::LEVEL_CHECKS

Constants included from ActiveSupport::ColorizeLogging

ActiveSupport::ColorizeLogging::BLACK, ActiveSupport::ColorizeLogging::BLUE, ActiveSupport::ColorizeLogging::CYAN, ActiveSupport::ColorizeLogging::GREEN, ActiveSupport::ColorizeLogging::MAGENTA, ActiveSupport::ColorizeLogging::MODES, ActiveSupport::ColorizeLogging::RED, ActiveSupport::ColorizeLogging::WHITE, ActiveSupport::ColorizeLogging::YELLOW

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveSupport::EventReporter::LogSubscriber

#emit, event_log_level, #logger, subscription_filter

Methods included from ActiveSupport::ColorizeLogging

#color, #colorize_logging, #debug, #fatal, #mode_from, #unknown, #warn

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Class Method Details

.default_loggerObject



191
192
193
# File 'activejob/lib/active_job/log_subscriber.rb', line 191

def self.default_logger
  ActiveJob::Base.logger
end

Instance Method Details

#bulk_enqueued(event) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'activejob/lib/active_job/log_subscriber.rb', line 49

def bulk_enqueued(event)
  payload = event[:payload]

  info do
    if payload[:enqueued_count] == payload[:job_count]
      enqueued_jobs_message(event)
    elsif payload[:enqueued_count] > 0
      if payload[:failed_enqueue_count] == 0
        enqueued_jobs_message(event)
      else
        "#{enqueued_jobs_message(event)}. "\
          "Failed enqueuing #{payload[:failed_enqueue_count]} #{'job'.pluralize(payload[:failed_enqueue_count])}"
      end
    else
      "Failed enqueuing #{payload[:failed_enqueue_count]} #{'job'.pluralize(payload[:failed_enqueue_count])} "\
        "to #{payload[:adapter]}"
    end
  end
end

#completed(event) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'activejob/lib/active_job/log_subscriber.rb', line 81

def completed(event)
  payload = event[:payload]

  if payload[:exception_class]
    cleaned_backtrace = backtrace_cleaner.clean(payload[:exception_backtrace])
    error do
      "Error performing #{payload[:job_class]} (Job ID: #{payload[:job_id]}) from #{queue_name(event)} in #{payload[:duration]}ms: #{payload[:exception_class]} (#{payload[:exception_message]}):\n" + Array(cleaned_backtrace).join("\n")
    end
  elsif payload[:aborted]
    error do
      "Error performing #{payload[:job_class]} (Job ID: #{payload[:job_id]}) from #{queue_name(event)} in #{payload[:duration]}ms: a before_perform callback halted the job execution"
    end
  else
    info do
      "Performed #{payload[:job_class]} (Job ID: #{payload[:job_id]}) from #{queue_name(event)} in #{payload[:duration]}ms"
    end
  end
end

#discarded(event) ⇒ Object



123
124
125
126
127
128
129
# File 'activejob/lib/active_job/log_subscriber.rb', line 123

def discarded(event)
  payload = event[:payload]

  error do
    "Discarded #{payload[:job_class]} (Job ID: #{payload[:job_id]}) due to a #{payload[:exception_class]} (#{payload[:exception_message]})."
  end
end

#enqueued(event) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'activejob/lib/active_job/log_subscriber.rb', line 11

def enqueued(event)
  payload = event[:payload]

  if payload[:exception_class]
    error do
      "Failed enqueuing #{payload[:job_class]} to #{queue_name(event)}: #{payload[:exception_class]} (#{payload[:exception_message]})"
    end
  elsif payload[:aborted]
    info do
      "Failed enqueuing #{payload[:job_class]} to #{queue_name(event)}, a before_enqueue callback halted the enqueuing execution."
    end
  else
    info do
      "Enqueued #{payload[:job_class]} (Job ID: #{payload[:job_id]}) to #{queue_name(event)}" + args_info(event)
    end
  end
end

#enqueued_at(event) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'activejob/lib/active_job/log_subscriber.rb', line 30

def enqueued_at(event)
  payload = event[:payload]

  if payload[:exception_class]
    error do
      "Failed enqueuing #{payload[:job_class]} to #{queue_name(event)}: #{payload[:exception_class]} (#{payload[:exception_message]})"
    end
  elsif payload[:aborted]
    info do
      "Failed enqueuing #{payload[:job_class]} to #{queue_name(event)}, a before_enqueue callback halted the enqueuing execution."
    end
  else
    info do
      "Enqueued #{payload[:job_class]} (Job ID: #{payload[:job_id]}) to #{queue_name(event)} at #{event[:payload][:scheduled_at]}" + args_info(event)
    end
  end
end

#interrupt(event) ⇒ Object



132
133
134
135
136
137
138
# File 'activejob/lib/active_job/log_subscriber.rb', line 132

def interrupt(event)
  payload = event[:payload]

  info do
    "Interrupted #{payload[:job_class]} (Job ID: #{payload[:job_id]}) #{payload[:description]} (#{payload[:reason]})"
  end
end

#resume(event) ⇒ Object



141
142
143
144
145
146
147
# File 'activejob/lib/active_job/log_subscriber.rb', line 141

def resume(event)
  payload = event[:payload]

  info do
    "Resuming #{payload[:job_class]} (Job ID: #{payload[:job_id]}) #{payload[:description]}"
  end
end

#retry_scheduled(event) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'activejob/lib/active_job/log_subscriber.rb', line 101

def retry_scheduled(event)
  payload = event[:payload]

  info do
    if payload[:exception_class]
      "Retrying #{payload[:job_class]} (Job ID: #{payload[:job_id]}) after #{payload[:executions]} attempts in #{payload[:wait_seconds]} seconds, due to a #{payload[:exception_class]} (#{payload[:exception_message]})."
    else
      "Retrying #{payload[:job_class]} (Job ID: #{payload[:job_id]}) after #{payload[:executions]} attempts in #{payload[:wait_seconds]} seconds."
    end
  end
end

#retry_stopped(event) ⇒ Object



114
115
116
117
118
119
120
# File 'activejob/lib/active_job/log_subscriber.rb', line 114

def retry_stopped(event)
  payload = event[:payload]

  error do
    "Stopped retrying #{payload[:job_class]} (Job ID: #{payload[:job_id]}) due to a #{payload[:exception_class]} (#{payload[:exception_message]}), which reoccurred on #{payload[:executions]} attempts."
  end
end

#started(event) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'activejob/lib/active_job/log_subscriber.rb', line 70

def started(event)
  payload = event[:payload]

  info do
    enqueue_info = payload[:enqueued_at].present? ? " enqueued at #{payload[:enqueued_at]}" : ""

    "Performing #{payload[:job_class]} (Job ID: #{payload[:job_id]}) from #{queue_name(event)}" + enqueue_info + args_info(event)
  end
end

#step(event) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'activejob/lib/active_job/log_subscriber.rb', line 172

def step(event)
  payload = event[:payload]

  if payload[:interrupted]
    info do
      "Step '#{payload[:step]}' interrupted at cursor '#{payload[:cursor]}' for #{payload[:job_class]} (Job ID: #{payload[:job_id]}) in #{payload[:duration]}ms"
    end
  elsif payload[:exception_class]
    error do
      "Error during step '#{payload[:step]}' at cursor '#{payload[:cursor]}' for #{payload[:job_class]} (Job ID: #{payload[:job_id]}) in #{payload[:duration]}ms: #{payload[:exception_class]} (#{payload[:exception_message]})"
    end
  else
    info do
      "Step '#{payload[:step]}' completed for #{payload[:job_class]} (Job ID: #{payload[:job_id]}) in #{payload[:duration]}ms"
    end
  end
end

#step_skipped(event) ⇒ Object



150
151
152
153
154
155
156
# File 'activejob/lib/active_job/log_subscriber.rb', line 150

def step_skipped(event)
  payload = event[:payload]

  info do
    "Step '#{payload[:step]}' skipped #{payload[:job_class]}"
  end
end

#step_started(event) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
# File 'activejob/lib/active_job/log_subscriber.rb', line 159

def step_started(event)
  payload = event[:payload]

  info do
    if payload[:resumed]
      "Step '#{payload[:step]}' resumed from cursor '#{payload[:cursor]}' for #{payload[:job_class]} (Job ID: #{payload[:job_id]})"
    else
      "Step '#{payload[:step]}' started for #{payload[:job_class]} (Job ID: #{payload[:job_id]})"
    end
  end
end