Sha256: f88e3393a1664aa28157436551af76402248bfbdaa1f98e3e6127b1cc234bf0a

Contents?: true

Size: 593 Bytes

Versions: 3

Compression:

Stored size: 593 Bytes

Contents

# frozen_string_literal: true

require "active_support/core_ext/time/calculations"

module Loggery
  module Util
    def log_job_runtime(job_type, job_instance_name)
      job_name = "Job type #{job_type} - #{job_instance_name}"

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loggery-0.3.0 lib/loggery/util.rb
loggery-0.2.1 lib/loggery/util.rb
loggery-0.2.0 lib/loggery/util.rb