Module: Loggery::Util

Included in:
Metadata::Middleware::Sidekiq
Defined in:
lib/loggery/util.rb

Instance Method Summary collapse

Instance Method Details

#log_job_runtime(job_type, job_instance_name = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/loggery/util.rb', line 5

def log_job_runtime(job_type, job_instance_name = nil)
  job_name = ["Job type #{job_type}", job_instance_name].compact.join " - "

  Rails.logger.info event_type: :"#{job_type}_started", message: "#{job_name} started"

  begin
    start_time = Time.current
    yield if block_given?
  ensure
    end_time = Time.current
    duration = end_time - start_time

    Rails.logger.info event_type: :"#{job_type}_finished",
                      message: "#{job_name} finished",
                      duration: duration
  end
end