Class: ActiveJob::LogSubscriber

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

Overview

:nodoc:

Constant Summary

Constants inherited from ActiveSupport::LogSubscriber

ActiveSupport::LogSubscriber::BLACK, ActiveSupport::LogSubscriber::BLUE, ActiveSupport::LogSubscriber::BOLD, ActiveSupport::LogSubscriber::CLEAR, ActiveSupport::LogSubscriber::CYAN, ActiveSupport::LogSubscriber::GREEN, ActiveSupport::LogSubscriber::MAGENTA, ActiveSupport::LogSubscriber::RED, ActiveSupport::LogSubscriber::WHITE, ActiveSupport::LogSubscriber::YELLOW

Instance Attribute Summary

Attributes inherited from ActiveSupport::Subscriber

#patterns

Instance Method Summary collapse

Methods inherited from ActiveSupport::LogSubscriber

#finish, flush_all!, log_subscribers, #start

Methods inherited from ActiveSupport::Subscriber

attach_to, detach_from, #finish, #initialize, method_added, #start, subscribers

Constructor Details

This class inherits a constructor from ActiveSupport::Subscriber

Instance Method Details

#discard(event) ⇒ Object


93
94
95
96
97
98
99
100
# File 'activejob/lib/active_job/log_subscriber.rb', line 93

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

  error do
    "Discarded #{job.class} due to a #{ex.class}."
  end
end

#enqueue(event) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'activejob/lib/active_job/log_subscriber.rb', line 7

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_at(event) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'activejob/lib/active_job/log_subscriber.rb', line 26

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


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

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

  info do
    if ex
      "Retrying #{job.class} in #{wait.to_i} seconds, due to a #{ex.class}."
    else
      "Retrying #{job.class} in #{wait.to_i} seconds."
    end
  end
end

#perform(event) ⇒ Object


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

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


45
46
47
48
49
50
# File 'activejob/lib/active_job/log_subscriber.rb', line 45

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


84
85
86
87
88
89
90
91
# File 'activejob/lib/active_job/log_subscriber.rb', line 84

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

  error do
    "Stopped retrying #{job.class} due to a #{ex.class}, which reoccurred on #{job.executions} attempts."
  end
end