Module: Resque::Plugins::RestashLogger

Defined in:
lib/restash_rails/resque/plugins/restash_logger.rb

Instance Method Summary collapse

Instance Method Details

#after_enqueue_logstash_logger(*args) ⇒ Object

Executed on the enqueueing instance



22
23
24
# File 'lib/restash_rails/resque/plugins/restash_logger.rb', line 22

def after_enqueue_logstash_logger(*args)
  log 'Enqueued', args, :debug
end

#after_perform_logstash_logger(*args) ⇒ Object



11
12
13
14
# File 'lib/restash_rails/resque/plugins/restash_logger.rb', line 11

def after_perform_logstash_logger(*args)
  @job_end_time = Time.now
  log 'Finished', args, :debug
end

#after_schedule_send_monitor_data(*args) ⇒ Object



26
27
28
# File 'lib/restash_rails/resque/plugins/restash_logger.rb', line 26

def after_schedule_send_monitor_data(*args)
  log 'Scheduled', args, :debug
end

#before_perform_logstash_logger(*args) ⇒ Object

Executed on the Resque worker



5
6
7
8
9
# File 'lib/restash_rails/resque/plugins/restash_logger.rb', line 5

def before_perform_logstash_logger(*args)
  @resque_job_uuid = SecureRandom.uuid
  @job_start_time = Time.now
  log 'Executing', args, :debug
end

#log(log_message, args, severity = :info) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/restash_rails/resque/plugins/restash_logger.rb', line 30

def log(log_message, args, severity = :info)
  extra_data = args.is_a?(Array) ? args.last : args
  log_arguments = { log_message: log_message, extra_data: extra_data, class: self.name, log_tag: :resque_hooks }
  if args.is_a?(Array) && args.first.is_a?(Exception)
    exception = args.first
    log_arguments[:exception] = { class: exception.class.to_s, message: exception.message.to_s, backtrace: exception.backtrace }
  end
  log_arguments[:exec_run_time] = @job_end_time - @job_start_time if @job_start_time.present? && @job_end_time.present?
  log_arguments[:resque_job_uuid] = @resque_job_uuid if @resque_job_uuid.present?
  Rails.logger.send(severity, log_arguments)
end

#on_failure_logstash_logger(*args) ⇒ Object



16
17
18
19
# File 'lib/restash_rails/resque/plugins/restash_logger.rb', line 16

def on_failure_logstash_logger(*args)
  @job_end_time = Time.now
  log 'Failed', args, :error
end