Class: ActiveJob::LogSubscriber
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveSupport::LogSubscriber
|
Defined in: | activejob/lib/active_job/log_subscriber.rb |
Constant Summary
::ActiveSupport::LogSubscriber
- Inherited
BLACK, BLUE, CYAN, GREEN, LEVEL_CHECKS, MAGENTA, MODES, RED, WHITE, YELLOW
Class Attribute Summary
::ActiveSupport::LogSubscriber
- Inherited
::ActiveSupport::Subscriber
- Inherited
Class Method Summary
::ActiveSupport::LogSubscriber
- Inherited
.attach_to, | |
.flush_all! | Flush all log_subscribers’ logger. |
.log_subscribers, .new, .fetch_public_methods, .set_event_levels, .subscribe_log_level |
::ActiveSupport::Subscriber
- Inherited
.attach_to | Attach the subscriber to a namespace. |
.detach_from | Detach the subscriber from a namespace. |
.method_added | Adds event subscribers for all new methods added to the class. |
.new, .subscribers, .add_event_subscriber, .fetch_public_methods, .find_attached_subscriber, .invalid_event?, .pattern_subscribed?, .prepare_pattern, .remove_event_subscriber |
Instance Attribute Summary
::ActiveSupport::LogSubscriber
- Inherited
::ActiveSupport::Subscriber
- Inherited
Instance Method Summary
- #discard(event)
- #enqueue(event)
- #enqueue_all(event)
- #enqueue_at(event)
- #enqueue_retry(event)
- #perform(event)
- #perform_start(event)
- #retry_stopped(event)
- #args_info(job) private
- #enqueue_source_location private
- #enqueued_jobs_message(adapter, enqueued_jobs) private
- #error(progname = nil, &block) private
- #format(arg) private
- #info(progname = nil, &block) private
- #log_enqueue_source private
- #logger private
- #queue_name(event) private
- #scheduled_at(event) private
::ActiveSupport::LogSubscriber
- Inherited
#call, #logger, #publish_event, #silenced?, | |
#color | Set color by using a symbol or one of the defined constants. |
#log_exception, #mode_from |
::ActiveSupport::Subscriber
- Inherited
Constructor Details
This class inherits a constructor from ActiveSupport::LogSubscriber
Class Attribute Details
.backtrace_cleaner (rw)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 7
class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new
.backtrace_cleaner? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/log_subscriber.rb', line 7
class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new
Instance Attribute Details
#backtrace_cleaner (rw)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 7
class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new
#backtrace_cleaner? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/log_subscriber.rb', line 7
class_attribute :backtrace_cleaner, default: ActiveSupport::BacktraceCleaner.new
Instance Method Details
#args_info(job) (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 145
def args_info(job) if job.class.log_arguments? && job.arguments.any? " with arguments: " + job.arguments.map { |arg| format(arg).inspect }.join(", ") else "" end end
#discard(event)
[ GitHub ]#enqueue(event)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 9
def enqueue(event) job = event.payload[:job] ex = event.payload[:exception_object] || job.enqueue_error if ex error do "Failed enqueuing #{job.class.name} to #{queue_name(event)}: #{ex.class} (#{ex.})" 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)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 49
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 (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 (adapter, enqueued_jobs) else "#{ (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 #{ActiveJob.adapter_name(adapter)}" end end end
#enqueue_at(event)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 29
def enqueue_at(event) job = event.payload[:job] ex = event.payload[:exception_object] || job.enqueue_error if ex error do "Failed enqueuing #{job.class.name} to #{queue_name(event)}: #{ex.class} (#{ex.})" 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)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 105
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.})." else "Retrying #{job.class} (Job ID: #{job.job_id}) after #{job.executions} attempts in #{wait.to_i} seconds." end end end
#enqueue_source_location (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 199
def enqueue_source_location Thread.each_caller_location do |location| frame = backtrace_cleaner.clean_frame(location) return frame if frame end nil end
#enqueued_jobs_message(adapter, enqueued_jobs) (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 207
def (adapter, enqueued_jobs) enqueued_count = enqueued_jobs.size job_classes_counts = enqueued_jobs.map(&:class).tally.sort_by { |_k, v| -v } "Enqueued #{enqueued_count} #{'job'.pluralize(enqueued_count)} to #{ActiveJob.adapter_name(adapter)}"\ " (#{job_classes_counts.map { |klass, count| "#{count} #{klass}" }.join(', ')})" end
#error(progname = nil, &block) (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 183
def error(progname = nil, &block) return unless super if ActiveJob.verbose_enqueue_logs log_enqueue_source end end
#format(arg) (private)
[ GitHub ]#info(progname = nil, &block) (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 175
def info(progname = nil, &block) return unless super if ActiveJob.verbose_enqueue_logs log_enqueue_source end end
#log_enqueue_source (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 191
def log_enqueue_source source = enqueue_source_location if source logger.info("↳ #{source}") end end
#logger (private)
[ GitHub ]#perform(event)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 86
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.}):\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)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 76
def perform_start(event) info do job = event.payload[:job] enqueue_info = job.enqueued_at.present? ? " enqueued at #{job.enqueued_at.utc.iso8601(9)}" : "" "Performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)}" + enqueue_info + args_info(job) end end
#queue_name(event) (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 141
def queue_name(event) ActiveJob.adapter_name(event.payload[:adapter]) + "(#{event.payload[:job].queue_name})" end
#retry_stopped(event)
[ GitHub ]#scheduled_at(event) (private)
[ GitHub ]# File 'activejob/lib/active_job/log_subscriber.rb', line 167
def scheduled_at(event) Time.at(event.payload[:job].scheduled_at).utc end