Class: ActiveJob::LogSubscriber

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#discard(event) ⇒ Object



128
129
130
131
132
133
134
135
# File 'activejob/lib/active_job/log_subscriber.rb', line 128

def discard(event)
  job = event.payload[:job]
  ex = event.payload[:error]

  error do
    "Discarded #{job.class} (Job ID: #{job.job_id}) due to a #{ex.class} (#{ex.message})."
  end
end

#enqueue(event) ⇒ Object



10
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 10

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

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

#enqueue_all(event) ⇒ Object



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

def enqueue_all(event)
  info do
    jobs = event.payload[:jobs]
    adapter = event.payload[:adapter]
    enqueued_count = event.payload[:enqueued_count]

    if enqueued_count == jobs.size
      enqueued_jobs_message(adapter, jobs)
    elsif jobs.any?(&:successfully_enqueued?)
      enqueued_jobs = jobs.select(&:successfully_enqueued?)

      failed_enqueue_count = jobs.size - enqueued_count
      if failed_enqueue_count == 0
        enqueued_jobs_message(adapter, enqueued_jobs)
      else
        "#{enqueued_jobs_message(adapter, enqueued_jobs)}. "\
          "Failed enqueuing #{failed_enqueue_count} #{'job'.pluralize(failed_enqueue_count)}"
      end
    else
      failed_enqueue_count = jobs.size - enqueued_count
      "Failed enqueuing #{failed_enqueue_count} #{'job'.pluralize(failed_enqueue_count)} to #{adapter_name(adapter)}"
    end
  end
end

#enqueue_at(event) ⇒ Object



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

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

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

#enqueue_retry(event) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'activejob/lib/active_job/log_subscriber.rb', line 103

def enqueue_retry(event)
  job = event.payload[:job]
  ex = event.payload[:error]
  wait = event.payload[:wait]

  info do
    if ex
      "Retrying #{job.class} (Job ID: #{job.job_id}) after #{job.executions} attempts in #{wait.to_i} seconds, due to a #{ex.class} (#{ex.message})."
    else
      "Retrying #{job.class} (Job ID: #{job.job_id}) after #{job.executions} attempts in #{wait.to_i} seconds."
    end
  end
end

#perform(event) ⇒ Object



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

def perform(event)
  job = event.payload[:job]
  ex = event.payload[:exception_object]
  if ex
    error do
      "Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: #{ex.class} (#{ex.message}):\n" + Array(ex.backtrace).join("\n")
    end
  elsif event.payload[:aborted]
    error do
      "Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: a before_perform callback halted the job execution"
    end
  else
    info do
      "Performed #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms"
    end
  end
end

#perform_start(event) ⇒ Object



76
77
78
79
80
81
# File 'activejob/lib/active_job/log_subscriber.rb', line 76

def perform_start(event)
  info do
    job = event.payload[:job]
    "Performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} enqueued at #{job.enqueued_at}" + args_info(job)
  end
end

#retry_stopped(event) ⇒ Object



118
119
120
121
122
123
124
125
# File 'activejob/lib/active_job/log_subscriber.rb', line 118

def retry_stopped(event)
  job = event.payload[:job]
  ex = event.payload[:error]

  error do
    "Stopped retrying #{job.class} (Job ID: #{job.job_id}) due to a #{ex.class} (#{ex.message}), which reoccurred on #{job.executions} attempts."
  end
end